我遇到了一些麻烦,艾特知道如何实现它。 我有3个型号:论坛,主题,帖子 我应该在论坛/索引
中显示所有帖子的汇总def index
@forums = Forum.all
end
- @forums.each do |forum|
tr.dotted
td.yach
= image_tag('forumico.png')
u = link_to forum.name, forum_path(forum)
br
p = forum.desc
td = forum.topics.count
td = forum.topics.post.count !!!!!!!!!!!!!!!
undefined method `post' for #<Topic
class Forum
has_many :topics, dependent: :destroy
class Post
belongs_to :topic
belongs_to :user
class Topic
belongs_to :forum
has_many :posts, dependent: :destroy
belongs_to :user
答案 0 :(得分:0)
您是否尝试过使用直通关系
class Forum
has_many :topics, dependent: :destroy
has_many :posts, through: :topics
然后您应该能够:
forum.posts.count
答案 1 :(得分:0)
如果您需要一些帖子,您可以更改以下内容
$file= fopen(yourFile.txt, "w");
fwrite($file, $stringUploaded);
fclose($file);
答案 2 :(得分:-1)