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