title: Rails nested resource form
body: <p>My project has users who can create activities and rate others' activities. I use an _activity partial in two views: one to list the users' own activities and one to list others' activities the user hasn't yet rated. In the latter case, I also include a form to rate that activity. It should submit to the ratings model with the current user's ID, the activity's ID and their rating. How can I get the activity id since their is no @activity variable, just an @activities collection which renders the partial for each member? Should I switch to an each method?</p>
  
  <p>Here is my code so far:</p>
  
  <p>for the user's own activity index:</p>
  
  <pre><code>class ActivitiesController &lt; ApplicationController
  
  def index
      @user = current_user
      @activities = @user.activities.paginate(page: params[:page], :per_page =&gt; 10).order(created_at: :desc)
  end
  </code></pre>
  
  <p>for their page of others' activities to rate:</p>
  
  <pre><code>def not_rated
      @user = current_user
      @activities = Activity.not_rated(current_user).paginate(page: params[:page], :per_page =&gt; 10).order(created_at: :desc)
      @rating = Rating.new
  end
  </code></pre>
  
  <p>The second of the two views that calls the partial (not_rated.html.erb):</p>
  
  <pre><code>&lt;div class="rate_activities"&gt;
          &lt;h3&gt; Rate Activities! (&lt;%= @activities.count %&gt;)&lt;/h3&gt;
          &lt;% if @activities.any? %&gt;
              &lt;%= render @activities %&gt;
              &lt;%= will_paginate @activities %&gt;
              &lt;% end %&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>The _activity partial:</p>
  
  <pre><code>&lt;ul class="activities" &gt;
  &lt;li class="activity"&gt;
      &lt;span class="content"&gt;&lt;%= activity.content %&gt;&lt;/span&gt;
      &lt;span class="timestamp"&gt;&lt;%= time_ago_in_words(activity.created_at) %&gt; ago&lt;/span&gt;
      &lt;% unless activity.user_id == @user.id %&gt;
          &lt;%= form_for([@rating, activity]) :url =&gt; new_activity_rating_path do |f| %&gt;
              &lt;p&gt;&lt;%= f.text_field :rating %&gt;&lt;/p&gt;
              &lt;%= f.submit "Submit my Activity", class: "mybutton" %&gt;
          &lt;% end %&gt;
      &lt;% end %&gt;
  
  &lt;/li&gt;
  </code></pre>
  
  <p></p>
  
  <p>Thanks!!</p>