Note that there are some explanatory texts on larger screens.

plurals
  1. PONested resource issue
    primarykey
    data
    text
    <p>I am struggling to pass an id successfully into my URL for the nested resource I have set up called Jobs.</p> <p>The error I am getting when I try to pass the <code>@job</code> object into my link is as follows:</p> <pre><code> No route matches {:action=&gt;"edit", :controller=&gt;"jobs", :user_id=&gt;1, :id=&gt;nil} </code></pre> <p>Which clearly shows it can't find the id correctly and so is finding <code>nil</code></p> <p>At the moment I have my routes setup as so:</p> <pre><code> resources :users do resources :jobs end </code></pre> <p>and the link I have is <code>&lt;%= link_to "Edit", edit_user_job_path(@user.id,@job) %&gt;</code></p> <p>What is interesting is that if I pass the object <code>@jobs</code> with an 's' on the end it will load the page correctly but when I click on the link will try and add all of that users job id's. </p> <p>In my controller for edit I have:</p> <pre><code>def edit @user = current_user @job = @user.jobs.find(params[:id]) end </code></pre> <p>Any help really would be much appreciated :)</p> <p><strong>UPDATE</strong></p> <p>Okay I was defining the object on the wrong page of my controller (under edit instead of index). The issue I am now having is <code>Couldn't find Job without an ID</code></p> <p>I updated my controller index definition to:</p> <pre><code> def index @user = current_user @jobs = @user.jobs.all @job = @user.jobs.find(params[:id]) end </code></pre> <p>And have in my view (jobs#index)</p> <pre><code>&lt;% @jobs.each do |f| %&gt; ... &lt;%= link_to "Edit", edit_user_job_path(@user.id,job) %&gt; ... &lt;% end %&gt; </code></pre> <p>Any advice would be much appreciated if you know where I am going wrong :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload