2012-12-06 38 views
2

我使用Rails Inherited_resource宝石在我的意见控制器评论时,设置当前用户和评论是一个嵌套的资源,以便:
资源:项目做
   资源:备注,请
结束
创建与inherited_resource轨

我也有评论控制器belongs_to的:
belongs_to的:项目:取景器=>:find_by_project_uuid !,:CLASS_NAME => “Thfz ::工程”,多态=>真

  1. 我怎样才能设置评论的用户关联的CURRENT_USER(USER_ID)时,其产生的?由于user_id不是被认为是大量分配的。

  2. 我尝试以下操作:
    高清begin_of_association_chain
              CURRENT_USER
    结束
    这并正确设置用户ID,但我不能让嵌套的资源项目正在与此。

  3. 同样的问题来当破坏一个评论,我需要找到通过CURRENT_USER的评论,所以如何实现这一目标?

所以我必须写我自己的创建和销毁的行动?

谢谢:)

回答

2

你试过以下里面comments_controller?

class CommentsController < InheritedResources::Base 
    before_filter :authenticate_user! # Assuming you are using Devise for authentication 
    respond_to :html, :xml, :json 

    belongs_to :project, :finder => :find_by_project_uuid!, :class_name => "Thfz::Project" 

    def create 
    @comment = build_resource 
    @comment.author = current_user 

    create! 
    end 
end