views:

335

answers:

3

I am looking to reproduce the following with Formtastic:

<% form_tag '/search', :method => 'get' do %>
  <%= text_field_tag :q, params[:q] %>
<% end %>

So far I have:

<% semantic_form_for :search, :html => { :method => :get } do |form| %>
  <% form.inputs do %>
    <%= form.input :q %>
  <% end %>
<% end %>

However, this requires access to the parameter hash using:

params[:search][:q]

Instead of my required:

params[:q]

I'd like to use Formtastic for all forms in the application I am working on, and so far I have only had problems with this one. Any ideas?

+2  A: 

Formtastic's semantic_form_for is wrapped around Rails' form_for, which only allows "model" forms like the one you're describing. I'm pretty sure you mean "desired" rather than "required", because it's pretty easy to access params[:search][:q] or duplicate the value to params[:q] yourself.

Justin French
Hi Justin. It is indeed a 'desired' request. I do have a mobile client interface that posts to the same route using params[:q], however I can add a hack around. Also, thanks for creating Formastic! The GEM is amazing!
Kevin Sylvestre
+1  A: 

<%= form.input :q, :input_html => { :name => 'q' } %>

Ebrahim