title: Rails - passing parameters in link_to
body: <p>My Accounts index page lists all accounts, and per account has a link to "+ Service"; this should direct the user to the /my_services/new page and have pre-populated the account_id field with the appropriate ID, depending on which link was clicked on the Accounts index page.</p>
  
  <p>I have debug(params) at the bottom of every page, and with what I'm trying, I'm not getting anything other than :controller and :action showing up in my parameters for the /my_services/new page.</p>
  
  <p>The link I've been trying is this:</p>
  
  <pre><code>link_to "+ Service", "my_services/new", :account_id =&gt; acct.id
  </code></pre>
  
  <p>I then also have logic in the services controller:</p>
  
  <pre><code>def new
    @my_service = MyService.new
    if params[:account_id]
      @my_service.account_id = params[:account_id]
    end
  end
  </code></pre>
  
  <p>Can someone help with the proper way of doing this? I haven't yet been able to get it going with with a few nasty little hacky things I tried.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Turns out, if someone is looking at this answer in future, nested resources (possibly with the <code>shallow: true</code> option in routes.rb) seem to be the way to go. My routes.rb for this part now looks like this:</p>
  
  <pre><code>resources :accounts, shallow: true do
    resources :services
  end
  </code></pre>
  
  <p>My links now look like this:</p>
  
  <pre><code>&lt;%= link_to "+ Service", new_service_path(:service =&gt; { :account_id =&gt; @account.id } ) %&gt;
  </code></pre>