2011-08-16 94 views

回答

0

你的表格结构如何?

例如:

= 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 
相关问题