开发者

Rails Rendering Issue

开发者 https://www.devze.com 2023-04-10 06:47 出处:网络
Whenever I\'m trying to render the games partial, the view it\'s being rendered in gives a nil return.

Whenever I'm trying to render the games partial, the view it's being rendered in gives a nil return.

here is the games partial:

<%= flash[:notice] %>
     <tr> 
     <% @games.each do |game| %>
       <td><%= gam开发者_JAVA百科e.name %></td> 

       <td><%= link_to('Pick!', vote_up_game_path(game.id), :method => :post) %></td> 
     </tr> 
       <% end %>


You should pass @games as a local variable to the partial. Consider looking at the documentation on its usage. I also feel the flash-notice should not belong inside the partial. You might also want to correct your code

<% games.each do |game| %>
  <tr> 
    <td><%= game.name %></td> 
    <td><%= link_to 'Pick!', vote_up_game_path(game.id), :method => :post  %></td> 
  </tr> 
<% end %>

You would render the partial as follows

<%= render :partial => "game_partial", :locals => { :games => @games } %>

It is also important to ensure @games isn't nil. If it is, you will still get your error - you should check your controller; typically I'd imagine your controller would have @games = Game.all, of course this is dependent on your particular implementation.

0

精彩评论

暂无评论...
验证码 换一张
取 消