帮助Rails项目快速实现搜索
本软件可以帮助Rails项目快速实现搜索/过滤页面。具体使用,请参照软件主页里的说明。
-
Include gem into Gemfile
gem 'rails-simple-search'
-
Code in model (app/model/search.rb):
class Search < RailsSimpleSearch::Base end
-
Code in controller:
@search = Search.new(User, params[:search]) @search.order = 'email' # optional @users = @search.run
-
Code in views:
<% form_for @search, url => "/xxxxxx" do |f| %> <%=f.label :email %> <%=f.text_field :email %> <%=f.label :state%> <%=f.select "address.state_id", [['AL', 1], ...] %> <!-- address is an association of model User --> <%=f.label :post%> <%=f.text_field "posts.comments.author" %> <!-- the associations could go even deeper, isn't it POWERFUL? --> <%=f.submit %> <% end %> <% @users.each do |user| %> <%= # show the attributes of user %> <% end %>
-
Add route for the post to url “/xxxxxx” (config/route.rb)
match "/xxxxxx" => "yyyyyyy#zzzzzz"
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!