俱乐部是一个模特儿,在那里我储存学生的课堂信息。
我有以下协会:
class Club < ActiveRecord::Base
has_many :mcqs
end
class Mcq < ActiveRecord::Base
#validation
validates :topic, presence: true,length: { minimum: 5 }
validates :club, presence: true
#association
belongs_to :user
belongs_to :club
end这是我的俱乐部总监-
class ClubsController < ApplicationController
def student_show_index
@club = current_user.clubs
end
def student_show_topic
@club = current_user.clubs
@mcq = @club.mcqs
end
end我只想把一个俱乐部的所有麦基打印给一个学生。
以下是我对MCQ(student_show_topic)展示主题的看法。
<%= render 'assessment/type' %>
<h1>List of Topics</h1>
<div class="main-cont">
<div class="stream-cont">
<div class="stream-cont">
<% @mcq.each do |f| %>
<div class="feed-cont-title all-header">
<tr>
<td><%= f.topic %></td>
</tr>
</div>
<% end %>
</div>
</div>这是联想问题。我的俱乐部模式不能进入mcq模式。
这是我的错误,小姐。
NoMethodError in ClubsController#student_show_topic
undefined method `mcqs' for #<Club::ActiveRecord_Associations_CollectionProxy:0x007fb031e0cf48>
Extracted source (around line #81):
79 def student_show_topic
80 @club = current_user.clubs
81 @mcq = @club.mcqs
82 end
83
84 end之后我使用@mcq = @club.first.mcqs
它展示了那个俱乐部所有的麦基。但在我俱乐部的桌子上我把俱乐部指定为
所以,当我点击9-物理主题时,它只显示物理,mcq主题,等等。
发布于 2015-09-21 05:15:37
看你@club不是一个单一的对象,它是一个对象的集合,你不能用@club调用mcqs。
但是你可以打电话给@club.first.mcqs
https://stackoverflow.com/questions/32687771
复制相似问题