Rails 传统呈现命名空间内对象的部分



我想在应用程序/视图目录中找到一个由两个命名空间共享的部分。如何使用岛屿/show.html.haml 示例中所示的 Rails 约定将缺失的部分(丢失者或其他人)/树/树.html.haml 链接到树/树.html.haml?

config/routes.rb

namespace :lostees do
  resources :islands
end
namespace :others do
  resources :islands
end

app/controllers/lostees/islands_controller.rb

class Lostees::IslandsController < Lostees::BaseController
end

app/controllers/others/islands_controller.rb

class Others::IslandsController < Others::BaseController
end

app/views/trees/_tree.html.haml

= content_tag_for tree do
  = tree.name

app/views/lostees/islands/show.html.haml

%h2 The Island
%div Trees
= render island.trees
#=> Missing partial lostees/trees/tree

app/views/others/islands/show.html.haml

%h2 The Island
%div Trees
= render island.trees
#=> Missing partial others/trees/tree
您可能

已经想通了这一点,但是您应该能够通过以下方式执行此操作:

= render partial: "trees/tree", collection: island.trees

相关内容

  • 没有找到相关文章

最新更新