Ruby on Rails form path for a third model

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):

<%= form_for <WhatDoIPutHere?> do |f| %>
  <div class="field">
    <%= f.label :number %><br />
    <%= f.text_field :number %>
  <div class="actions">
    <%= f.submit %>
<% end %>

Now I know I need to run a rake routes to figure out the path. Here is my rake routes result:

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

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.

Thanks in advance for any help!


class JacksController < ApplicationController

  def create
    @switch = Switch.find(params[:switch_id])
    @jack = @switch.jacks.create(params[:jack])
    redirect_to switch_path(@switch)

  def destroy
    @switch = Switch.find(params[:switch_id])
    @jack = @switch.jacks.find(params[:id])
    redirect_to switch_path(@switch)



You can have nested forms for your nested models.

form_for @floor do |f|
  f.fields_for :switches do |g|
    g.fields_for :jacks do |h|
      h.label :number

Need Your Help

Different Database on same crystal report

c# sql-server oracle crystal-reports

I am running a Visual Studio application from two different databases SQL Server and Oracle.

Can I get content of WebView with accessibility features of android?

android webview accessibility

I am building a simple app that adds sound effect to other game app, and that game is running in hybrid app that contains WebView.