Ruby on rails RubyonRails-向帖子添加评论
我正在使用RubyonRails创建一个网站,允许用户提交菜谱。我称之为报复。我不确定如何允许用户添加评论(提交评论的用户可以编辑和删除评论)。 这是指向我的代码的链接: 我不确定这是否适合我: 如果我不清楚,请告诉我是否有任何代码我应该张贴 谢谢Ruby on rails RubyonRails-向帖子添加评论,ruby-on-rails,Ruby On Rails,我正在使用RubyonRails创建一个网站,允许用户提交菜谱。我称之为报复。我不确定如何允许用户添加评论(提交评论的用户可以编辑和删除评论)。 这是指向我的代码的链接: 我不确定这是否适合我: 如果我不清楚,请告诉我是否有任何代码我应该张贴 谢谢 你提供的两个链接都不起作用 你想要完成的事情很容易 这是一个简单的评论设置。这包括配方模型、注释模型和用户模型。所有这些模型都将相互关联 型号/配方.rb class Recipe < ApplicationRecord has_many
配方
模型、注释
模型和用户
模型。所有这些模型都将相互关联
型号/配方.rb
class Recipe < ApplicationRecord
has_many :comments
end
class User < ApplicationRecord
has_many :comments
end
class Comment < ApplicationRecord
belongs_to :recipe
belongs_to :user
end
类配方
型号/用户.rb
class Recipe < ApplicationRecord
has_many :comments
end
class User < ApplicationRecord
has_many :comments
end
class Comment < ApplicationRecord
belongs_to :recipe
belongs_to :user
end
class用户
models/comment.rb
class Recipe < ApplicationRecord
has_many :comments
end
class User < ApplicationRecord
has_many :comments
end
class Comment < ApplicationRecord
belongs_to :recipe
belongs_to :user
end
class注释
就像我说的,这是一个简单的评论设置。这不涉及授权或嵌套注释。这两个链接都位于登录或付费墙后面,因此没有提供太多上下文来提供答案。下面由用户Matt D提供的答案是一个很好的起点,但是没有代码示例,并且知道您遇到了什么问题(视图、模型、控制器等),这个问题的范围可能相当大