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

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

Вопрос

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?

Это было полезно?

Решение

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 %>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top