Created
June 29, 2014 13:38
-
-
Save elricstorm/006c074cc9d94bb77f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AjaxController < ApplicationController | |
skip_authorization_check | |
def ncaa_teams | |
if params[:search] | |
like= "%".concat(params[:search].concat("%")) | |
teams = NcaaTeam.where("name like ?", like) | |
else | |
teams = NcaaTeam.all | |
end | |
list = teams.map {|u| Hash[ id: u.id, label: u.name, name: u.name]} | |
render json: list | |
end | |
def nfl_teams | |
if params[:search] | |
like= "%".concat(params[:search].concat("%")) | |
teams = NflTeam.where("name like ?", like) | |
else | |
teams = NflTeam.all | |
end | |
list = teams.map {|u| Hash[ id: u.id, label: u.name, name: u.name]} | |
render json: list | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*= require myfoundation/foundation | |
*= require site | |
*= require responsive-tables | |
*= require jquery.ui.autocomplete | |
*= require administration | |
*= require users | |
*= require subscriptions | |
*= require ncaa | |
*= require nfl | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//= require jquery | |
//= require jquery.ui.autocomplete | |
//= require jquery_ujs | |
//= require responsive-tables | |
//= require foundation | |
//= require jquery.purr | |
//= require best_in_place | |
//= require sticky_footer | |
$(document).ready -> | |
$('#ncaa_team_name').autocomplete({source: "/ajax/ncaa_teams"}); | |
$('#nfl_team_name').autocomplete({source: "/ajax/nfl_teams"}); | |
$(function(){ $(document).foundation(); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model for NcaaTeam | |
def ncaa_team_name=(name) | |
team = NcaaTeam.find_by_name(name) | |
if team | |
self.team_id = team.id | |
else | |
errors[:team_name] << "Invalid name entered" | |
end | |
end | |
def ncaa_team_name | |
NcaaTeam.find(team_id).name if team_id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# model for NflTeam | |
def nfl_team_name=(name) | |
team = NflTeam.find_by_name(name) | |
if team | |
self.team_id = team.id | |
else | |
errors[:team_name] << "Invalid name entered" | |
end | |
end | |
def nfl_team_name | |
NflTeam.find(team_id).name if team_id | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class="has-form"> | |
<div class="row collapse"> | |
<div class="small-12 columns"> | |
<div class="centered"> | |
<%= form_tag nfl_teams_path, :method => 'get' do %> | |
<p> | |
<%= text_field_tag :search, params[:search], id: "nfl_team_name", placeholder: 'Find a Team' %> | |
<%= submit_tag "Search", :name => nil, class: 'round button tiny' %> | |
</p> | |
<% end %> | |
</div> | |
</div> | |
</div> | |
</li> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment