Created
January 26, 2012 12:29
-
-
Save anonymous/1682561 to your computer and use it in GitHub Desktop.
search
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 LoginController < ApplicationController | |
def search | |
@student = Student.search params[:search] | |
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
<%form_tag(:controller => 'login', :action => 'overview', :method => 'get') do %>> | |
<%= text_field_tag :search, params[:search], :id => 'search_field' %> | |
<%= submit_tag "Search", :name => nil %> | |
<%= link_to_function "Clear", "$('search_field').clear()" %> | |
<% end %> | |
<div id="search"> | |
<%= render :partial => 'search' %> | |
</div> | |
<ul> | |
<% @student.each do |student| %> | |
<li><%= link_to student.student_name,:action => 'show', :id => student.id %></li> | |
</ul> | |
<%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 | |
class Student < ActiveRecord::Base | |
def self.search(query) | |
#find(:all, :conditions => ['student_name LIKE ?', "%#{query}%"]) || [] | |
self.find(:all, :conditions => ['student_name LIKE ?', "%#{query}%"]) | |
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
# You can have the root of your site routed with map.root -- just remember to delete public/index.html. | |
map.root :controller => "login", :action => 'login' | |
map.users 'users', :controller => :users | |
map.students 'students', :controller => :students | |
map.login 'login', :controller => :login, :action => :login | |
map.logout 'logout', :controller => :login, :action => :logout | |
#map.main_menu 'main_menu', :controller => :login, :action => :main_menu | |
map.home 'home', :controller => :login, :action => :home | |
map.overview 'overview', :controller => :login, :action => :overview | |
map.retention 'retention', :controller => :login, :action => :retention | |
map.reports 'reports', :controller => :login, :action => :reports | |
map.tracking 'tracking', :controller => :login, :action => :tracking | |
# See how all your routes lay out with "rake routes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment