Ruby on rails 未定义的方法'each';对于nil:nilclasseajax&;多模型

Ruby on rails 未定义的方法'each';对于nil:nilclasseajax&;多模型,ruby-on-rails,ruby,Ruby On Rails,Ruby,我试图找到一个答案,但没有运气 “我的页面”的索引设置为“模型频道/索引”。通道/索引呈现部分通道/索引 到目前为止一切正常。当我添加第二个模型时,它的工作原理与我的第一个模型非常相似,我基本上复制了所有内容并更改了所有参数。然后,必须在通道/索引中呈现第二个模型“Apply”的索引。但是模型apply也有一个部分_索引,它在applies/索引上呈现 这会产生以下错误: nil:NilClass的未定义方法'each' <%= @applies.each do |apply| %>

我试图找到一个答案,但没有运气

“我的页面”的索引设置为“模型频道/索引”。通道/索引呈现部分通道/索引

到目前为止一切正常。当我添加第二个模型时,它的工作原理与我的第一个模型非常相似,我基本上复制了所有内容并更改了所有参数。然后,必须在通道/索引中呈现第二个模型“Apply”的索引。但是模型apply也有一个部分_索引,它在applies/索引上呈现

这会产生以下错误: nil:NilClass的未定义方法'each'

<%= @applies.each do |apply| %>
    <h5><%= link_to apply.name, apply_path(apply), remote: true %><h5>

<% end %>

这是我的申请/索引

<%= link_to "Apply for membership", new_apply_path, remote: true %>

<%= render :partial => "applies/index" %>
<%= @applies.each do |apply| %>
    <h5><%= link_to apply.name, apply_path(apply), remote: true %><h5>

<% end %>
<%= render "applies/index" %>

<%= link_to "Create new Channel", new_channel_path, remote: true %>

      <div class="channel-index"> 
     <%= render "index" %>
    </div>
<% @channels.each do |channel| %>
    <h5><%= link_to channel.name, channel_path(channel), remote: true %><h5>

<% end %>

“应用/索引”%>
应用/\u索引

<%= link_to "Apply for membership", new_apply_path, remote: true %>

<%= render :partial => "applies/index" %>
<%= @applies.each do |apply| %>
    <h5><%= link_to apply.name, apply_path(apply), remote: true %><h5>

<% end %>
<%= render "applies/index" %>

<%= link_to "Create new Channel", new_channel_path, remote: true %>

      <div class="channel-index"> 
     <%= render "index" %>
    </div>
<% @channels.each do |channel| %>
    <h5><%= link_to channel.name, channel_path(channel), remote: true %><h5>

<% end %>

频道/索引

<%= link_to "Apply for membership", new_apply_path, remote: true %>

<%= render :partial => "applies/index" %>
<%= @applies.each do |apply| %>
    <h5><%= link_to apply.name, apply_path(apply), remote: true %><h5>

<% end %>
<%= render "applies/index" %>

<%= link_to "Create new Channel", new_channel_path, remote: true %>

      <div class="channel-index"> 
     <%= render "index" %>
    </div>
<% @channels.each do |channel| %>
    <h5><%= link_to channel.name, channel_path(channel), remote: true %><h5>

<% end %>

频道/\u索引

<%= link_to "Apply for membership", new_apply_path, remote: true %>

<%= render :partial => "applies/index" %>
<%= @applies.each do |apply| %>
    <h5><%= link_to apply.name, apply_path(apply), remote: true %><h5>

<% end %>
<%= render "applies/index" %>

<%= link_to "Create new Channel", new_channel_path, remote: true %>

      <div class="channel-index"> 
     <%= render "index" %>
    </div>
<% @channels.each do |channel| %>
    <h5><%= link_to channel.name, channel_path(channel), remote: true %><h5>

<% end %>

频道控制器

class ChannelsController < ApplicationController

  def index
    @channels = Channel.all.order("created_at ASC")
  end

  def show
    @channel = Channel.find(params[:id])
  end

  def new
    @channel = Channel.new
  end

  def create 
    @channel = Channel.create(channel_params)
    @channels = Channel.all


  end

  def edit
    @channel = Channel.find(params[:id])
  end

  def update
    @channel.update_attributes(channel_params)
    @channels = Channel.all
    @channel = Channel.find(params[:id])


  end

  def delete
    @channel = Channel.find(params[:channel_id])
  end

  def destroy
    @channel = Channel.find(params[:id])
    @channels = Channel.all
    @channel.destroy

  end

private
  def channel_params
    params.require(:channel).permit(:name, :description)
  end

end
class AppliesController < ApplicationController

  def index
    @applies = Apply.all.order("created_at ASC")
  end

  def show
    @apply = Apply.find(params[:id])
  end

  def new
    @apply = Apply.new
  end

  def create 
    @apply = Apply.create(apply_params)
    @applies = Apply.all


  end

  def edit
    @apply = Apply.find(params[:id])
  end

  def update
    @apply.update_attributes(apply_params)
    @applies = Apply.all
    @apply = Apply.find(params[:id])


  end

  def delete
    @apply = Apply.find(params[:apply_id])
  end

  def destroy
    @apply = Apply.find(params[:id])
    @applies = Apply.all
    @apply.destroy

  end

private
  def apply_params
    params.require(:apply).permit(:name, :email, :website)
  end

end
类通道控制器
应用控制器

class ChannelsController < ApplicationController

  def index
    @channels = Channel.all.order("created_at ASC")
  end

  def show
    @channel = Channel.find(params[:id])
  end

  def new
    @channel = Channel.new
  end

  def create 
    @channel = Channel.create(channel_params)
    @channels = Channel.all


  end

  def edit
    @channel = Channel.find(params[:id])
  end

  def update
    @channel.update_attributes(channel_params)
    @channels = Channel.all
    @channel = Channel.find(params[:id])


  end

  def delete
    @channel = Channel.find(params[:channel_id])
  end

  def destroy
    @channel = Channel.find(params[:id])
    @channels = Channel.all
    @channel.destroy

  end

private
  def channel_params
    params.require(:channel).permit(:name, :description)
  end

end
class AppliesController < ApplicationController

  def index
    @applies = Apply.all.order("created_at ASC")
  end

  def show
    @apply = Apply.find(params[:id])
  end

  def new
    @apply = Apply.new
  end

  def create 
    @apply = Apply.create(apply_params)
    @applies = Apply.all


  end

  def edit
    @apply = Apply.find(params[:id])
  end

  def update
    @apply.update_attributes(apply_params)
    @applies = Apply.all
    @apply = Apply.find(params[:id])


  end

  def delete
    @apply = Apply.find(params[:apply_id])
  end

  def destroy
    @apply = Apply.find(params[:id])
    @applies = Apply.all
    @apply.destroy

  end

private
  def apply_params
    params.require(:apply).permit(:name, :email, :website)
  end

end
class AppliesController

提前非常感谢

将此添加到通道控制器并应用控制器

  def index
    @channels = Channel.all.order("created_at ASC")
    @applies = Apply.all.order("created_at ASC")
  end

为什么我会得到命名错误…顺便说一句,你几乎从来都不想将
每个
应该是
,否则你会在输出中得到意外的字符串化数组。是的-我知道,这是个错误,哈哈。