[英]undefined method and attr_accessor
I want to collect data from an input which is not in my model. 我想从不在模型中的输入中收集数据。 So, I tried to use a "attr_accessor" but it's don't work and I don't know why ... There is the line in my controller :
因此,我尝试使用“ attr_accessor”,但是它不起作用,我也不知道为什么...我的控制器中有一行:
attr_accessor :nbr_blocs
And there are few parts from my form (made with simpleform) : 从我的表单(用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 %>
And my error is : " undefined method `nbr_blocs' " 我的错误是:“ 未定义的方法'nbr_blocs' ”
What can I do ? 我能做什么 ? Thank you for your help.
谢谢您的帮助。
From SimpleForm docs : 来自SimpleForm docs :
#input(attribute_name, options = {}, &block) ⇒ Object
So, :nbr_blocs
must be a attribute from @newsletter
, not a Controller accessor. 所以,
:nbr_blocs
必须从属性@newsletter
,而不是一个控制器访问。 I guess you can use simple_fields_for
for an input that is not in your model, nut I am not sure: 我想您可以将
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.