Cannot solve "ArgumentError: Missing block" when calling form_for in Rails namespaced Controller

StackOverflow https://stackoverflow.com/questions/14443356

Pregunta

In the admin panel of an app, there should be a new form introduced. I wanted to make use of 2.3 Relying on Record Identification as described in RoR Guide, but if I say

form_for(@product)

or

form_for [:backend, @product]

it throws an ArgumentError: Missing block. This is for the backend-new function, which the controller in controller/backend/product_controller defines via

 def new
   @product = Product.new
end

What did I do wrong? Why is this not working?

¿Fue útil?

Solución

You need to pass a do block to the form_for: (See the documentation: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html)

For example:

<%= form_for(@product) do |f| %>
  <%= f.label :name %>
  <%= f.text_field :name %>
  <%= f.submit %>
<% end %>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top