Rails常规使用命名空间内的对象进行部分渲染

时间:2014-04-04 18:47:25

标签: ruby-on-rails ruby-on-rails-3 actionview

我想在app / views目录中找到一个部分由两个名称空间共享。如何使用islands / show.html.haml示例中显示的Rails约定将缺失的部分(失败者或其他人)/trees/tree.html.haml链接到trees / tree.html.haml?

配置/ routes.rb中

namespace :lostees do
  resources :islands
end

namespace :others do
  resources :islands
end

应用程序/控制器/ lostees / islands_controller.rb

class Lostees::IslandsController < Lostees::BaseController
end

应用程序/控制器/其他的/ islands_controller.rb

class Others::IslandsController < Others::BaseController
end

应用程序/视图/树木/ _tree.html.haml

= content_tag_for tree do
  = tree.name

应用程序/视图/ lostees /岛/ show.html.haml

%h2 The Island

%div Trees
= render island.trees

#=> Missing partial lostees/trees/tree

应用程序/视图/其他的/岛/ show.html.haml

%h2 The Island

%div Trees
= render island.trees

#=> Missing partial others/trees/tree

1 个答案:

答案 0 :(得分:1)

你可能已经想到了这一点,但你应该可以这样做:

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