Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top