Skip to content

Instantly share code, notes, and snippets.

Created January 26, 2012 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1682561 to your computer and use it in GitHub Desktop.
Save anonymous/1682561 to your computer and use it in GitHub Desktop.
search
class LoginController < ApplicationController
def search
@student = Student.search params[:search]
end
<%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%>
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
# 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