| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

帮助Rails项目快速实现搜索

本软件可以帮助Rails项目快速实现搜索/过滤页面。具体使用,请参照软件主页里的说明。

  1. Include gem into Gemfile

    gem 'rails-simple-search'
  2. Code in model (app/model/search.rb):

    class Search < RailsSimpleSearch::Base  end
  3. Code in controller:

    @search = Search.new(User, params[:search])  @search.order = 'email'  # optional  @users = @search.run
  4. 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 %>
  5. Add route for the post to url “/xxxxxx” (config/route.rb)

    match "/xxxxxx" => "yyyyyyy#zzzzzz"

项目主页:http://www.open-open.com/lib/view/home/1355578447416

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1355578447416.html
Rails Ruby开发