It's Synatx issue it's f.text_field
form_for structure for namespaced resource in index view
-
28-09-2022 - |
Pergunta
I've tried to follow the Rails docs when constructing a form_for
under a namespace.
The pecularity with my case is that I'm rendering one form for each object instance, all together in the index
view (see code below).
Why do I get the following error message:
"undefined method `textfield' for # < ActionView::Helpers::FormBuilder:0x00000103f04188>"
routes.rb:
namespace :admin do
resources :plans
end
controllers/admin/plans_controller.rb:
def index
@plans = Plan.all
end
views/admin/plans/index.html.erb:
<table>
<thead>
<tr>
<th>Title</th>
<th></th>
</tr>
</thead>
<tbody>
<% @plans.each do |plan| %>
<tr>
<%= form_for [:admin, plan] do |f| %>
<td><%= f.textfield :title %></td>
<td><%= f.submit "Save" %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
Solução
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow