加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – div_for:NoMethodError

发布时间:2020-12-17 01:29:16 所属栏目:百科 来源:网络整理
导读:我正在尝试一个ror教程,我遇到了以下代码行: 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
我正在尝试一个ror教程,我遇到了以下代码行:

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

我想修改index.html.erb,这样就不需要部分但是它无法正常工作.

请参阅下面的代码.

index.html.erb:

<% div_for @players do %>
<%= @player.FNAME %> <%= @player.SURNAME %>
<% end %>

玩家#index中的NoMethodError

解决方法

这是您的代码的直接翻译:

<% @players.each do |player| %>
  <% div_for player do %>
    <%= player.FNAME %> <%= player.SURNAME %>
  <% end %>
<% end %>

渲染:部分给定一个集合(@players this case)将逐个遍历集合并为您渲染部分.

但渲染集合也会为您提供计数器和间隔模板.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读