开发者

how can I pass parametrs from file.haml with ruby on rails?

开发者 https://www.devze.com 2023-03-28 21:09 出处:网络
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?

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
0

精彩评论

暂无评论...
验证码 换一张
取 消