开发者

Check if a layout exists in Rails?

Is there a s开发者_StackOverflow社区tandard 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'
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜