Frage

I would like to put a form on one of my pages, but don't want to use form_for to update a model. I am basically using this like a filtering/searching system, where the user inputs something, and the page changes based on what the user input. I know this is a pretty simple problem, but I'm also a little new to Rails.

Note: I have the ability to filter the results if I can just get the input value. I just need access to the input value in my Controller.

War es hilfreich?

Lösung

Just use form_for with a symbol as argument rather than an instance variable.

You can access the form data in your controller by referencing your params, just like you normally would. Let's say you have a form kinda like this:

<%= form_for :search do |f| %>
  <%= f.text_field :query %>
  <%= f.submit %>
<% end %>

You'll then get the contents of the search form by calling params[:search][:query] in your controller.

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for

Andere Tipps

you need meta_search

<%= form_for @search, :url => articles_path, :html => {:method => :get} do |f| %>
  <%= f.label :title_contains %>
  <%= f.text_field :title_contains %><br />
  <%= f.label :comments_created_at_greater_than, 'With comments after' %>
  <%= f.datetime_select :comments_created_at_greater_than, :include_blank => true %><br />
  <!-- etc... -->
  <%= f.submit %>
<% end %>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top