I have a Users controller and a layout called 'users.html.haml'. The problem I'm having is that Rails does not seem to find the users layout automatically. I have to tell every action in the Users controller to render the lay开发者_如何学Goout. If I don't tell the action which layout to use, it renders no layout at all.
Currently, the layout renders only if the controller action has this line:
render :layout=>'users.html.haml'
Any ideas? Thanks in advance.
UPDATE: I'm an idiot. I overwrote the "initialize" method in application controller, and it was causing all layouts to be loaded improperly unless I specifically told the action which layout to use. Didn't have anything to do with haml after all. Thanks for all your answers.
You havev the users.html.haml in your
app/views/layouts
directory right? And not your app/views/users directory?
Try using this:
render :layout=>'users'
NOTE: I have removed the .haml.html part, because that isn't necessary
Other this you can do is to have the layout in top of the controller, like
layout 'users'
Edit: and like @Noli said, your layouts should be in app/views/layouts path
精彩评论