Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby on Rails form path for a third model
    primarykey
    data
    text
    <p>I'm working on a map for the network in my building. I have the separate floor models working, which list each switch when you click on the show method. Then I would like to have it so you can click on each switch to see the jack numbers on each switch port. I have the view for the switch working thanks to another question I've asked, but now I'm stuck trying to show the jacks in that same show. Here is my partial for the jacks (app/views/jacks/_jacks.html.erb):</p> <pre><code>&lt;%= form_for &lt;WhatDoIPutHere?&gt; do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :number %&gt;&lt;br /&gt; &lt;%= f.text_field :number %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>Now I know I need to run a rake routes to figure out the path. Here is my rake routes result:</p> <pre><code>floor_switch_jacks GET /floors/:floor_id/switches/:switch_id/jacks(.:format) jacks#index POST /floors/:floor_id/switches/:switch_id/jacks(.:format) jacks#create new_floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/new(.:format) jacks#new edit_floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/:id/edit(.:format) jacks#edit floor_switch_jack GET /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#show PUT /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#update DELETE /floors/:floor_id/switches/:switch_id/jacks/:id(.:format) jacks#destroy floor_switches GET /floors/:floor_id/switches(.:format) switches#index POST /floors/:floor_id/switches(.:format) switches#create new_floor_switch GET /floors/:floor_id/switches/new(.:format) switches#new edit_floor_switch GET /floors/:floor_id/switches/:id/edit(.:format) switches#edit floor_switch GET /floors/:floor_id/switches/:id(.:format) switches#show PUT /floors/:floor_id/switches/:id(.:format) switches#update DELETE /floors/:floor_id/switches/:id(.:format) switches#destroy floors GET /floors(.:format) floors#index POST /floors(.:format) floors#create new_floor GET /floors/new(.:format) floors#new edit_floor GET /floors/:id/edit(.:format) floors#edit floor GET /floors/:id(.:format) floors#show PUT /floors/:id(.:format) floors#update DELETE /floors/:id(.:format) floors#destroy home_index GET /home/index(.:format) home#index root / home#index </code></pre> <p>My question is how do I read the rake routes to find the proper syntax for the form_for line? I had this same problem getting my switch view to work in the first place. If this is an easy question and there is a guide out there feel free to just send me to that instead. I can't seem to find one specific to to this.</p> <p>Thanks in advance for any help!</p> <p>EDIT:</p> <pre><code>class JacksController &lt; ApplicationController def create @switch = Switch.find(params[:switch_id]) @jack = @switch.jacks.create(params[:jack]) redirect_to switch_path(@switch) end def destroy @switch = Switch.find(params[:switch_id]) @jack = @switch.jacks.find(params[:id]) @jack.destroy redirect_to switch_path(@switch) end end </code></pre>
    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.
    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