【发布时间】:2014-08-24 06:46:08
【问题描述】:
我在保存用户发送的数据并在我的视图文件中使用它时遇到问题,我在其他主题中找不到解决方案。
这是我通过表单选择日期的代码:
<%= select( 'resource', 'field', @benchmark.compositions.find(:all).collect {|u| [u.date_composition] }, :prompt => 'Selected date') %>
这是我获得此选择的控制器:
def sample_method
@resource_field = params[:resource][:field]
end
这是我在 routes.rb 文件中的一行:
match 'benchmark/sample_method/:resource/:field', :controller => 'benchmarks', :action => 'sample_method'
现在我想在我的视图中使用选定的值,所以我输入:
<% @resource_field = @benchmark.find(params[:resource][:field]) %>
但它说
ActionView::Template::Error (undefined method `[ ]' for nil:NilClass)
请问如何使用我选择的值?
【问题讨论】:
标签: ruby-on-rails view controller