我的申请中有很多分页;它们看起来都很相像;除了一个工作以外都很好。一个破碎的一个在最后一步中断。详情如下。我有3个类 - Micropost,Category,Selection。我有一个指向details_controller的链接,它提供了一个视图/选择/详细信息列表,它反过来呈现部分/选择/详细信息。代码成功进入最后一个视图并在第三行中断,错误消息“未定义的局部变量或方法`micropost'用于#<#< 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
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
查看链接
details_controller
<li>
<span class="selection">
<%= selection.content %>
   
( <%= selection.count %> )
   
<%= link_to "Details", controller: :details, param1: selection.id, param2: selection.category_id %>
</span>
</li>
查看:/ selections / detailslist
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
查看:选择/详细信息
<% @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 %>
错误讯息: 未定义的局部变量或方法`micropost'用于#&lt;#&lt;类:0x007fed1811ba90&GT;:0x007fed17bc9fb0&GT;