简体   繁体   中英

how to load view path from a gem in rails

I am working on a rails app and it requires multiple layouts.

I came up with a solution and said, i don't want my users to go into the stress of using a template engines such as liquid to customize their own private layout. i want to give them a verity of awesome layouts to select from.

Now i want to build multiple view directory as a gem so if the users page is not using the application layout, rails loads the view path from the gem using the name of the layout selected to find the right gem to load from(All layouts will consist of the name of the gem for simplicity)

How can i tell rails which view path to use based of layout selected by the user so rails can load the exact gem's view path given that there are multiple view paths for the various gems gems.

you could provide a rails-engine as a gem. rails looks up the views from the engine when they are not found in the application. have a look at the docs: http://edgeguides.rubyonrails.org/engines.html#overriding-views

这帮助我解决了问题,并避免了创建gem的需要

prepend_view_path "#{Rails.root}/app/views/customlayout"

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