Reputation: 79228
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.
Upvotes: 7
Views: 4198
Reputation: 3357
You can use template_exists? which is an alias for exists?
For example: template_exists?("layout_name", "layouts")
Upvotes: 25
Reputation: 15492
I think the better way would be store these values in a database, let a user choose from that.
Instead of trying to verify through what has been suggested in the previous post.
Use a Layout Model and let the user choose.
Upvotes: 0
Reputation: 20367
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'
}
Upvotes: 3