Is there a standard way to check if a view layout exists from within a Controller in Rails? I'm trying to allow the user to determine the layout, but it needs to exist first.
You can use template_exists? which is an alias for exists?
For example: template_exists?("layout_name", "layouts")
There is no standard public way as far as I know. You could use a rudimentary call like this:
layouts = Dir['app/views/layouts/*'].map {|f|
File.basename(f, '.html.erb') # returns 'layout' for 'layout.html.erb'
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With