views:

33

answers:

2

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.

A: 

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'
}
Daniel Beardsley
A: 

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.

Rishav Rastogi