comments_controller: def create @product = Product.find(params[:product_id])
@comment = @product.comments.create(comment_params) @comment.user_id = current_user.id redirect_to product_path(@product) end
comment——model
class Comment < ActiveRecord::Base
belongs_to :product
belongs_to :user
validates :product_id, presence: true
validates :content, presence: true, length: { maximum: 140 }
end
现在数据库中有 product_id 和 user_id,product_id 能够存进去而 user_id 我不知道该怎么存进去。。。。