index.html.erb:
p>
<%= render :partial => @players %>
_player.html.erb:
<% div_for player do% >
<%= player.FNAME %> <%= player.SURNAME %>
<% end %>
players_controller.rb:
p>
def index
@players = Player.all(:order => "FNAME")
respond_to do |format|
format.html
end
end
I want to modify index.html.erb so that the part is not needed but it does not work properly.
Please refer to the code below.
index .html.erb:
<% div_for @players do %>
<%= @player.FNAME %> <%= @player.SURNAME %>< br /><% end %>
NoMethodError in player#index
<% @players.each do |player| %>
<% div_for player do %>
<%= player.FNAME %> <%= player.SURNAME %>
<% end %>
<% end %>
Rendering: Partially given A collection (@players this case) will traverse the collection one by one and render parts for you.
But the rendering collection will also provide you with counter and interval templates.
I am trying a ror tutorial, and I came across the following line of code:
p>
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 index.html.erb so that the part is not needed but it does not work properly.< /p>
Please refer to the code below.
index.html.erb:
<% div_for @players do %>
<%= @player.FNAME %> <%= @player.SURNAME %>
<% end %>
NoMethodError in player#index
< p>
This is a direct translation of your code:
<% @players.each do |player| %>
<% div_for player do %>
<%= player.FNAME %> <%= player.SURNAME %>
<% end %>
<% end %>
Rendering: Partially given a collection (@players this case) will traverse the collection one by one and render the parts for you.
But the rendering collection will also provide you with counter and interval templates.