4

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?

JoshDM
  • 4,939
  • 7
  • 43
  • 72
Yo Ludke
  • 2,149
  • 2
  • 23
  • 38
  • Can you show us your whole `form_for` line? "Missing block" sound like you forgot to say `form_for @product do |f|` and then close the form with an `end`. – Austin Mullins Jan 21 '13 at 16:50

1 Answers1

5

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 %>
MrYoshiji
  • 54,334
  • 13
  • 124
  • 117
  • Yes, it solves the problem.. I just thought I could have more automagic, a settings db with a lot of columns to generate a form for this.. But while doing it manually it turned out that at a later point I would have to do it manually anyway :) – Yo Ludke Jan 24 '13 at 15:50