我的申请中有很多分页;它们看起来都一样;除了一个工作正常。一个坏了,一个在最后一步就坏了。详情如下。我有 3 个课程——Micropost、Category、Selection。我有一个指向 details_controller 的链接,它呈现一个视图 /selections/detailslist,该视图又呈现部分 /selections/details。代码成功到达最后一个视图并在第三行中断,并显示错误消息“未定义的局部变量或方法 `micropost' for #<#< Class: ....”这里的任何帮助将不胜感激。
class Micropost < ActiveRecord::Base
attr_accessible :content, :category_content, :selection_content, :category_id, :selection_id, :user_id
belongs_to :user
belongs_to :category
belongs_to :selection
validates :user_id, presence: true
validates :category_content, presence: true
validates :selection_content, presence: true
end
class Category < ActiveRecord::Base
attr_accessible :content, :id, :count, :c_count
has_many :selections
has_many :microposts
end
class Selection < ActiveRecord::Base
attr_accessible :content, :count, :category_id
belongs_to :category
has_many :microposts
end
带链接查看
<li>
<span class="selection">
<%= selection.content %>
   
( <%= selection.count %> )
   
<%= link_to "Details", controller: :details, param1: selection.id, param2: selection.category_id %>
</span>
</li>
details_controller
class DetailsController < ApplicationController
require 'will_paginate/array'
respond_to :html, :js
def index
#@category = Category.find_by_id(params[:param2])
@selection = Selection.find_by_id(params[:param1])
@microposts = @selection.microposts.paginate(page: params[:page])
render '/selections/detailslist'
end
end
查看:/selections/detailslist
<% @category = Category.find_by_id(@selection.category_id) %>
<h3> <%= @category.content %> </h3>
<br>
<%= @selection.content %>
 
( <%= @selection.count %> )
<br>
<ol class="selections">
<%= render partial: 'selections/details', collection: @microposts %>
</ol>
<%= will_paginate @microposts %>
查看:选择/详细信息
<li>
<span class="selection">
<% user = User.find_by_id(micropost.user_id) %>
<%= user.name %>
</span>
</li>
错误消息:#<#< Class:0x007fed1811ba90>:0x007fed17bc9fb0> 的未定义局部变量或方法 `micropost'