문제

I'd like to create a page where I can edit all my entries at once. For example, I have 10 devices, at that point, I'm creating a html table with at each row a device with the possibility to edit each line without having to do extra clicking.

I've already tried these things (index.html.erb)

<% @devices.each do |device| %>
<%= render 'form', locals: { device: @device }%>
or
<%= render 'form', :collection => :device %>
or
<%= render 'form', :device %>
<% end %>

And my form partial

<%= form_for @device do |f| %>
<td><%= f.submit %></td>
<td><%= f.name%></td>
<td><%= f.type</td>
<td>Style app</td>
<td></td>
<td></td>
<% end %>

But I'm still getting this error undefined method `model_name' for NilClass:Class

Does anyone have a clue?

Thanks

도움이 되었습니까?

해결책

From what you have tried it looks like you are very close. What if you try rendering it as a partial?

<% @devices.each do |device| %>
  <%= render partial: 'form', locals: { device: device } %>
<% end %>

Another difference here is the scope of the device param on the second line.

다른 팁

You need to change your partial... You are rendering global variable, you need to render local variable...

So, this is your solution:

<% @devices.each do |device| %>
<tr>
    <%= render 'form', locals: { device: device }%>
</tr>

and

<%= form_for device do |f| %>

Here, you should only be using the @ in @devices... Nowhere else.

Edit: Don't forget your <tr></tr>

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top