0

我正在为我的建筑物中的网络绘制地图。我有单独的地板模型工作,当您单击显示方法时,它会列出每个开关。然后我想拥有它,以便您可以单击每个交换机以查看每个交换机端口上的插孔号。由于我问了另一个问题,我对开关的工作有了看法,但现在我一直试图在同一个节目中展示千斤顶。这是我的千斤顶部分(app/views/jacks/_jacks.html.erb):

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

现在我知道我需要运行一个 rake 路线来找出路径。这是我的 rake 路线结果:

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

我的问题是如何阅读 rake 路线以找到 form_for 行的正确语法?我有同样的问题让我的切换视图首先工作。如果这是一个简单的问题,并且有一个指南,请随时将我发送给那个。我似乎找不到一个专门针对这个的。

提前感谢您的帮助!

编辑:

class JacksController < 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
4

1 回答 1

2

您可以为嵌套模型设置嵌套表单。

form_for @floor do |f|
  f.fields_for :switches do |g|
    g.fields_for :jacks do |h|
      h.label :number
    end
  end
end
于 2012-06-13T17:50:42.500 回答