Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access the ID of a resource already loaded via AJAX if not through the URL params in Rails 3?
    primarykey
    data
    text
    <p>If I have a situation where paramters aren't passed explicitly via the URL because there are some ajax elements on the one page, how do I access an ID for an object loaded much earlier....for instance. </p> <ol> <li>User selects client.id=1</li> <li>User selects, project.id=3</li> <li>User selects, stages.id=9</li> </ol> <p>But none of those IDs are passed through the URL. </p> <p>In that example, by the time the user reaches step 3, I would like to access the <code>client.id</code> in the Client controller....how do I do that ?</p> <p>If it were in the URL, I would just do <code>client = Client.find(params[:id])</code>, but if I do that now, by step 3, what gets returned as the ID parameter is the Stage ID - which is not what I want.</p> <p>This is what their actions in their respective controllers look like:</p> <pre><code>Client Step Action def step client = Client.find(params[:id]) projects = client.projects respond_to do |format| #format.html { redirect_to("/") } format.html { render :partial =&gt; "projects/show", :collection =&gt; projects, :as =&gt; :project, :layout =&gt; false, :status =&gt; :ok } end end Project Step Action def step project = Project.find(params[:id]) stages = project.stages respond_to do |format| format.html { render :partial =&gt; "stages/show", :collection =&gt; stages, :as =&gt; :stage, :layout =&gt; false, :status =&gt; :ok } end end Stage Step Action def step stage = Stage.find(params[:id]) uploads = stage.uploads respond_to do |format| format.html { render :partial =&gt; "uploads/show", :collection =&gt; uploads, :as =&gt; :upload, :layout =&gt; false, :status =&gt; :ok } end end </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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