ActionView::Template::Error: wrong number of arguments (Simple Form)

岁酱吖の 提交于 2020-07-22 21:41:41

问题


I have a Rails 4 app that always worked, but now a page with a simple_form_for is generating an error. I dropped all the code, leaving just the simple_form_for and still yet I'm getting error.

The page with errors (_form.html.erb):

<%= simple_form_for @anuncio do |f| %>
<%= f.input :titulo %>
<% end %>

When I execute this page, I get this error:

F, [2015-01-08T16:16:21.920151 #19971] FATAL -- : 
ActionView::Template::Error (wrong number of arguments (3 for 2)):
    1: <%= simple_form_for @anuncio do |f| %>
    2: <%= f.input :titulo %>
    3: <% end %>
  config/initializers/simple_form.rb:100:in `block (2 levels) in <top (required)>'
  app/views/anuncios/_form.html.erb:2:in `block in _app_views_anuncios__form_html_erb___4151327912554241759_53270140'
  app/views/anuncios/_form.html.erb:1:in `_app_views_anuncios__form_html_erb___4151327912554241759_53270140'
  app/views/anuncios/new.html.erb:3:in `_app_views_anuncios_new_html_erb___954346116733613916_53199500'

回答1:


I found the error. I have a custom def to render my label in my simple_form.rb (config/initializers/simple_form.rb). After a "bundle update", my simple_form gem was updated (to the 3.1.0 version, and also my actionview was update to the 4.2.0) and they change the arguments passed to my custom def, broken the app.

Before (config/initializers/simple_form.rb):

config.label_text = lambda { |label, required| "#{label}" }

Corrected:

config.label_text = lambda { |label, required, explicit_label| "#{label}" }


来源:https://stackoverflow.com/questions/27846952/actionviewtemplateerror-wrong-number-of-arguments-simple-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!