0
我有一个红宝石轨道上的haml文件。这是我的代码:我怎样才能通过ruby on rails从file.haml传递参数?
%p.form_row.actions
= submit_tag
我想在提交中发送参数。我怎样才能做到这一点?
我有一个红宝石轨道上的haml文件。这是我的代码:我怎样才能通过ruby on rails从file.haml传递参数?
%p.form_row.actions
= submit_tag
我想在提交中发送参数。我怎样才能做到这一点?
你的表格结构如何?
例如:
= form_tag(search_path, :method => "get") do
= label_tag(:q, "Search for:")
= text_field_tag(:q)
= submit_tag("Search")
即发起GET请求到search_path
途径(其在routes.rb
文件创建),并传递在称为:q
到控制器动作
所以如果参数在您的routes.rb
文件中有:
match :search, :to => 'my_controller#search', :via => [:get]
然后您的控制器ac和MyController#search
看起来像
def search
# this is the parameter passed in from the form
query_string = params[:q]
# now do something with the parameter...
end
你读过这个吗? http://guides.rubyonrails.org/form_helpers.html –
我尝试了几次,但没有成功 – Batty