Problem getting application.rhtml to work

Hi guys,

I'm a day into working on my very first Ruby on Rails app, so this is
probably something really silly I've overlooked.

I just want to get my entire app using a single layout (for now, at
least). Going by what came up from google searching, I created

/app/views/layouts/application.rhtml

which looks something like this:

<head>
  <title>Whelps - <%= ["In the ", controller.controller_name, " section
viewing the ", controller.action_name, " page."] %></title>
  <%= stylesheet_link_tag 'scaffold' %>
</head>
<body>

<!-- TODO: Header! Include navigation partail-->
<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>
<br />
<!-- Footer -->
<hr />
<br />
<p>
Have any problems, questions, or suggestions on Whelps?<br />
We'd greatly appreciate your <%= link_to "feedback", :controller =>
"feedback" %><br />
<br />
<small><em>Powered by <%= link_to "Ruby on Rails", :url =>
"http://www.rubyonrails.org" %><br />
&copy; Jordan Rastrick, 2006</em></small><br />
</p>
</body>
</html>

It works fine and dandy if I specify layout "application" at the
beginning of my controllers. However, if I don't specify this line at
the top of a given controller, I get an error when trying to reach it.

For example, theres the trivial
app/views/controllers/homepage_controller.rb:

class HomepageController < ApplicationController
    def user_permitted?(user)
        return true # Every user is permitted to visit their homepage
    end

    def index

    end
end

Trying to access /homepage gives:

ActionView::ActionViewError in HomepageController#index

No rhtml, rxml, rjs or delegate template found for layouts/homepage

However, from what I'd read, I'd been lead to believe that
"application.rhtml" would be used (by defaut) by the Application
Controller, and then this would be inherited by all controllers
decending from it (all my controllers do). I've renamed all the other
files in app/views/layouts, so that application.rhtml is the only rhtml
file present.

I know, its only a minor annoyance, but it seems to go against the
whole spirit of Rails (esp. DRY) that I'd have to specify the exact
same default layout in every single controller, so I figure I must be
doing something wrong somewhere. Perhaps the inheriting of layouts
behaviour has been deprecated, and/or replaced with something better?
The Rails API didn't offer any clues on this front.

Any pointers would be greatly appreciated.

Thanks,
Jordan Rastrick

That isn't needed as its the default layout template.

David Fitzgibbon wrote:

Maybe silly question but do you have 'layout "application"' in
app/controllers/application.rb?

--
Posted via http://www.ruby-forum.com/.

Yes, I do at the moment, but I've tried having it both there and not
there and I get the same error either way.

Hi Jordan,

Jordan wrote:

David Fitzgibbon wrote:

Maybe silly question but do you have 'layout "application"' in
app/controllers/application.rb?

Yes, I do at the moment, but I've tried having it both there and not
there and I get the same error either way.

I know you said you'd renamed your other layouts. Have you tried removing them from the directory? I know Rails checks extensions on Views, but I'm not sure about layouts. It's possible (and would be a bug) that it could get confused if it found a file with the 'right' name but the wrong extension. I hope you'll let us know. I've never seen this problem before.

Best regards,
Bill

Thanks Bill, this was the problem!

I'd renamed all the layouts along the lines of "homepage.rhtml" ->
"homepage.old". However renaming them further to "x_homepage.old"
solved the problem completely, giving exactly the behaviour I expected.

It does seem like rails must have been getting a bit confused - I'm
guess having a "homepage.xxx" file in layouts made
homepage_controller.rb think it had its own layout, but when it
actually went to fetch it, it couldnt find an rhtml file, so threw an
exception. Or something like that.

Should this be reported somewhere as a bug? I'm not really familiar
with this RoR community's bug tracking / reporting systems yet.

Thanks again for your help,
Jordan

Bill Walton wrote:

Jordan wrote:

Thanks Bill, this was the problem!

Excellent. Thanks for letting us know.

Should this be reported somewhere as a bug?

I would. Definitely. No telling if it will be accepted, especially if you submit it without a patch (and tests), but I'd say, at a minimum, the behavior needs to be recorded.

I'm not really familiar with this RoR community's
bug tracking / reporting systems yet.

No time like the present to get started :wink: The trail starts at http://www.rubyonrails.org

Best regards,
Bill