I have a haml file with ruby on rails. This is my code:
%p.form_row.actions
= submit_tag
I want to send parameters in submit. How can I 开发者_如何学Godo this?
What is your form structured like?
For example:
= form_tag(search_path, :method => "get") do
= label_tag(:q, "Search for:")
= text_field_tag(:q)
= submit_tag("Search")
That initiates a GET request to the search_path
route (which is created in the routes.rb
file) and passes in a parameter called :q
to the controller action
So if you had this in your routes.rb
file:
match :search, :to => 'my_controller#search', :via => [:get]
Then your controller action MyController#search
would look like
def search
# this is the parameter passed in from the form
query_string = params[:q]
# now do something with the parameter...
end
精彩评论