Check if layout exists in Rails?

Is there a standard way to check for a presentation layout inside a controller in Rails? I am trying to allow the user to define a layout, but it must exist first.

+7
ruby-on-rails views
source share
3 answers

As I know, there is no standard public method. You can use the rudimentary call as follows:

layouts = Dir['app/views/layouts/*'].map {|f| File.basename(f, '.html.erb') # returns 'layout' for 'layout.html.erb' } 
+2
source share

Can you use template_exists? which is an alias for exist?

For example: template_exists?("layout_name", "layouts")

+23
source share

I think the best way is to store these values ​​in a database, to allow the user to choose from this.

Instead of trying to verify what was suggested in the previous post.

Use the layout model and select the user.

0
source share

All Articles