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 :nbr_blocs
And there are few parts from my form (made with 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' "
What can I do ? Thank you for your help.
From SimpleForm docs :
#input(attribute_name, options = {}, &block) ⇒ Object
So, :nbr_blocs
must be a attribute from @newsletter
, not a Controller accessor. I guess you can use simple_fields_for
for an input that is not in your model, nut I am not sure:
<%= simple_form_for @newsletter do |f| %>
<%= f.input :attribute %>
<%= simple_fields_for :not_model do |n| %>
<%= n.input :nbr_blocs %>
<% end %>
<% end %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.