Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adding search to Casein
For example, to add search-by-email to a model called User
in views/casein/users/index.html.erb
<%= content_for :sidebar do %>
<li>
<%= form_tag casein_users_path, {:method => 'get'} do %>
<div class='form-group'>
<small><%= label_tag "search", "Search by email", {:class => "control-label"} %></small>
<%= text_field_tag "search", params[:search], {:class => "form-control", :size => "100%"} %>
</div>
<% end %>
</li>
<% end %>
in controllers/casein/users_controller.rb, expand index to be:
def index
if params[:search]
@casein_page_title = "Users (search for: #{params[:search]})"
@users = User.where(User.arel_table[:email].matches("%#{params[:search]}%")).order(sort_order("created_at")).paginate :page => params[:page]
else
@casein_page_title = 'Users'
@users = User.order(sort_order(:created_at)).paginate :page => params[:page]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment