简体   繁体   中英

Rendering controller/action within a different view

I am looking for a way in Ruby on Rails to render a completely different controller's action within other views.

For example I am writing a band website that displays their albums. So I have /albums/list that shows a list of all of their albums with other stuff around the page as the layout. Now what I am looking to do is also render /news/list in every page as part of the layout as well so that every page you go to you can see it.

I cannot find a way to call the news controller list action and display it in the list view using partial views. Any help would be appreciated.

http://api.rubyonrails.org/classes/ActionView/Helpers/RenderingHelper.html#method-i-render

render() method give you ability to render specific file, placed in any directory :)

also read this article - http://blog.plataformatec.com.br/2012/01/my-five-favorite-hidden-features-in-rails-3-2 especially about "Custom partial paths".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM