Hi
I know there are a lot of posts about the rails “dangerous” form_tag helper method, but why not another one.
Before saying anything about it, I want to write down the differences between form_tag and form_for (which was the choosen one previously). form_for is provided for updating data models and form_tag is provided for doing the other form operations (search something, change language in a page, etc).
Ok, after this, let’s go to the battle. This was my code
< % form_tag :controller => 'pages', :action => 'index' , :method => 'get' do %>
Tags : < %= text_field_tag :tags, '', :size => 40 %>
< %= submit_tag 'Search' %>
< % end %>
and I didn’t got the html code what I wanted to obtain, after googling for a while, I found this post which got me to the right way to see the light. The reason of this problem was that I was not using the right syntax for form_tag, which is
form_tag(url_for_options = {}, options = {}, *parameters_for_url, &block)
so my code became
< % form_tag({:controller => 'pages', :action => 'index'} , {:method => 'get'}) do %>
Tags : < %= text_field_tag :tags, '', :size => 40 %>
< %= submit_tag 'Search' %>
< % end %>
and I was happy again
Hope this silly problem helps not to waste your time (I did it for you
)
M.