I am trying an ror tutorial and I came across the following line of code:
index.html.erb:
<%= render :partial => @players %>
_player.html.erb:
<% div_for player do %>
<%= player.FNAME %> <%= player.SURNAME %>
<% end %>
players_controller.rb:
def index
@players = Player.all(:order => "FNAME")
respond_to do |format|
format.html
end
end
I want to modify the index.html.erb so that there is no need for a partial but it’s not working properly.
Please see code below.
index.html.erb:
<% div_for @players do %>
<%= @player.FNAME %> <%= @player.SURNAME %>
<% end %>
NoMethodError in Players#index
This is a direct translation of your code:
The
render :partialgiven a collection (@playersthis case) would walk through the collection one by one and render the partial for you.But rendering a collection also gives you a counter and spacer template too.