簡體   English   中英

未定義的方法和attr_accessor

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM