Frage

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?

War es hilfreich?

Lösung

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 %>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top