[英]undefined method and attr_accessor
我想从不在模型中的输入中收集数据。 因此,我尝试使用“ attr_accessor”,但是它不起作用,我也不知道为什么...我的控制器中有一行:
attr_accessor :nbr_blocs
从我的表单(用simpleform制作)中,几乎没有什么部分:
<%= simple_form_for @newsletter, method: "post", url: (gestion_newsletters_assist_step2_send_path) do |f| %>
[...]
<%= f.input :"nbr_blocs", :as => :integer, :input_html => { :maxlength => 2 } %>
[...]
<% end %>
我的错误是:“ 未定义的方法'nbr_blocs' ”
我能做什么 ? 谢谢您的帮助。
来自SimpleForm docs :
#input(attribute_name, options = {}, &block) ⇒ Object
所以, :nbr_blocs
必须从属性@newsletter
,而不是一个控制器访问。 我想您可以将simple_fields_for
用于模型中没有的输入,但我不确定:
<%= simple_form_for @newsletter do |f| %>
<%= f.input :attribute %>
<%= simple_fields_for :not_model do |n| %>
<%= n.input :nbr_blocs %>
<% end %>
<% end %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.