Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在为 Rails3 使用 Ransack Search Gem。有没有办法获取用户在搜索框中输入的搜索参数?
如有必要,我想在我的视图中提供它。
谢谢!
我最终弄清楚了:
类别控制器
def index @q = Category.search(params[:q]) @categories = @q.result(:distinct => true) end
查看/_form.html.erb
%= search_form_for @q do |f| %> <%= f.text_field :name_cont %> <% end %> <%= @q.name_cont %>
我缺少的部分是@q.name_cont。这将输出输入到搜索表单中的字符串。