2011-08-08 12 views
0

Railsのアクションの継承とネストされたリソース

resources :devices, :except => [:edit] do 
    resources :services, :only => [:index, :destroy], :controller => "devices/services" 
    resources :alerts, :only => [:index, :destroy], :controller => "devices/alerts" 
end 

は今、私が何をしたいデバイス/ショービューがネストされたため、「レイアウト」も持っています私が定義している他のサブアクションについては、 を参照してください。

だから私のデバイス/ show.html.erbは次のようになります言う:

<div class="resource"> 
    <div class="sidebar"> 
    <ul> 
     <li><%= active_link_to "General", @device, :active => :exclusive %></li> 
     <li><%= active_link_to "Services", device_services_path(@device) %></li> 
     <li><%= active_link_to "Alerts", device_alerts_path(@device) %></li> 
     etc.. 
    </ul> 
    </div> 
    <div class="data"> 
    <%= render "shared/flash_messages" %> 
    <%= yield %> 
    </div> 
</div> 

それでは、どのように私は、デバイス/アラート、サブビュー(デバイス/サービス/ index.html.erbをレンダリング行くのです/index.html.erb)ここで(仮説的な)利回りは#data divにありますか?

+0

あなたは何を持っていますか? – jamesc

+0

歩留まりはレイアウトAFAIKでのみ有効です。私はこれを試して、収量は何もレンダリングしていません... –

+1

あなたの質問は、利回りを使用する方法についてですか?その場合は、http://guides.rubyonrails.org/layouts_and_rendering.html#using-content_for – jamesc

答えて

0

あなたの質問は、継承とネストされたリソースとはまったく関係ないと思われます。

あなたが降伏コマンドを使用する方法を知りたい場合は、私はあなたの質問に私のコメントにリンクを掲示が、ここでは特に、あなたのコードの例である

<div class="resource"> 
    <div class="sidebar"> 
    <ul> 
     <li><%= active_link_to "General", @device, :active => :exclusive %></li> 
     <li><%= active_link_to "Services", device_services_path(@device) %></li> 
     <li><%= active_link_to "Alerts", device_alerts_path(@device) %></li> 
     etc.. 
    </ul> 
    </div> 
    <div class="data"> 
    <%= render "shared/flash_messages" %> 
    <%= yield :nested_resources %> 
    </div> 
</div> 

次に、あなたはそれで何かを配置したい場所にdivをcontent_for:nested_resourcesブロックにまとめます。 ビューテンプレートのどこかに

<% content_for :nested_resources do %> 
    <!-- whatever code you would normally have in your view template --> 
<% end %> 
関連する問題