我創建了一個搜索表單傳遞所有輸入爲單PARAMS
<%= form_tag url_for(:action => "index") do %>
<%= text_field_tag 'fromdate' %>
<%= text_field_tag 'todate' %>
<%= submit_tag 'Search' %>
<% end %>
我需要通過我的控制器來模擬所有這些值作爲一個PARAMS。這是我的控制器
def index
@client = Customer.search
#something like this @client = Customer.search(as_single_params)
respond_to do |format|
format.html
end
end
我該怎麼做?
您的觀點將在'params'散列返回屬性您需要從'params'哈希(例如,'params [:fromdate]')拉出屬性,並使用'Customer'數據上的這些參數執行合適的查詢。有關查詢界面的信息,請參閱http://guides.rubyonrails.org/active_record_querying.html。 – lurker
我不清楚你想要什麼比'Customer.search(params [:fromdate],params [:todate])更多'' – Shadwell
根據你的'Customer'模型,你也可以簡單地傳遞整個'params '哈希通過:'Customer.search(params)' –