title: Multiple Foreign Keys for Rails record - Unknown Action
body: <p>I'm working on an app that allows users to comment on a single "work" (think blog post). The associations in the models are as follows:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :works  
    has_many :comments
  
  class Work &lt; ActiveRecord::Base
    belongs_to :user
    has_many :comments
  
  
  class Comment &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :post
    belongs_to :work
  </code></pre>
  
  <p>In the comments table, a record has the following fields:</p>
  
  <p>id
  content<br>
  user_id<br>
  created_at<br>
  updated_at<br>
  work_id</p>
  
  <p>In my Comments controller, I have the following Create action:</p>
  
  <pre><code>def create
      @work = Work.find(params[:id])
      @comment = @work.comments.create(params[:comment])
      @comment.user = current_user
      if @comment.save
        #flash[:success] = "Post created!"
        redirect_to root_url
      else
        render 'activities'
      end
    end
  </code></pre>
  
  <p>I'm trying to associate both the user AND the work to the comment but I get the following error message when I try to create a comment:</p>
  
  <pre><code>Unknown action
  
  The action 'update' could not be found for CommentsController
  </code></pre>
  
  <p>I'm trying to use the following StackOverflow answer as a guide but the solution is not working for me: 
  <a href="https://stackoverflow.com/questions/5977267/multiple-foreign-keys-for-a-single-record-in-rails-3">Multiple Foreign Keys for a Single Record in Rails 3?</a></p>
  
  <p><strong>EDIT:</strong>
  I have a add comment form on the works#show action:</p>
  
  <pre><code>def show 
    @work = Work.find(params[:id])
    @comment = current_user.comments.create(params[:comment])
    @activities = PublicActivity::Activity.order("created_at DESC").where(trackable_type: "Work", trackable_id: @work).all
    @comments = @work.comments.order("created_at DESC").where(work_id: @work ).all 
      respond_to do |format|
        format.html # show.html.erb
        format.xml  { render :xml =&gt; @work }
      end
    end
  </code></pre>
  
  <p>The Comment form itself:</p>
  
  <pre><code>&lt;%= form_for(@comment) do |f| %&gt;
    &lt;%= render 'shared/error_messages', object: f.object %&gt;
    &lt;div class="field"&gt;
      &lt;%= f.text_area :content, placeholder: "Post a comment!" %&gt;
    &lt;/div&gt;
    &lt;%= f.submit "Post", class: "btn btn-small btn-primary" %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I also have an update method on the Comments controller:</p>
  
  <pre><code>def update
       @comment = current_user.comments.find(params[:id])
      if @comment.update_attributes(params[:comment])
        flash[:success] = "Comment updated"
        redirect_to @comment
      end
    end
  </code></pre>