render partial of another namespace

隐身守侯 提交于 2020-01-06 03:49:27

问题


I have a problem. I need to render objects using partials of another namespace.

 render complain.target

it tryes to render partial from current namespace(current is admin)

Missing partial admin/bulletins/bulletin...

I dont need to render it from admin/..

I cant specify partial path like

render partial: '/bulletins/bulletin', locals: { bulletin: complain.target }

But it's polymorphic association, and different partial pathes are used. Is it any way to do it? Thanks in advance!


回答1:


There seems to be no possible way to achieve this with a render complain.target call (Checked on Rails 5 source).

There is a config option for action_view to disable namespace prepending for partials, though:

     Rails.application.config.action_view.prefix_partial_path_with_controller_namespace = false



回答2:


You can use render "/#{complain.target.to_partial_path}"



来源:https://stackoverflow.com/questions/13376012/render-partial-of-another-namespace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!