I am attempting to build a simple content management system using Twitter’s Bootstrap for a small site and I’m running into an issue with the views.
Rails version is 3.0.10
I want to allow the user to create their own pages so I have a Pages controller that has all your standard RESTful methods. Since these can have crud applied to them, they can only be accessed by a logged-in administrator.
So… I have a Public controller that sets the @pages and @page instance variables and uses those to display them in the public Show view.
Here is the Public controller – pretty simple:
def index
@pages = Page.all
end
def show
@pages = Page.all
@page = Page.find(params[:id])
end
The reason that there is a @pages instance variable on the ‘index’ method is because I have a welcome page that loads and I’m passing in @pages to populate the navigation elements dynamically:
<div class="nav-collapse">
<ul class="nav">
<li><%= link_to "Welcome", public_index_path, :class => 'active', :id => 'menu_home' %></li>
<% @pages.each do |page| %>
<li><%= link_to page.title, public_path(page) %></li>
<% end %>
</ul>
</div><!--/.nav-collapse -->
The content of the Public controller’s ‘show’ method (which contains an individual page) is passed into the <%= yield %> statement in the applicaton.html.erb file:
<div class="container">
<%= yield %>
<hr>
<footer>
<p>My site</p>
</footer>
</div> <!-- /container -->
So far, this is working fine.
The problem is that when I click the link that takes me to the public_path(page) – I get the content as it should appear, but I lose all my styles. I’m actually getting a 404 error on my stylesheets:

All of these style sheets were loading in just fine on the http://localhost:3000/public page, but when it goes to http://localhost:3000/public/1 – that’s when all the styles disappear. But, they are both using the same layout.
Here is what the log file shows when the request is made:
Started GET "/public/1" for 127.0.0.1 at 2012-03-03 21:14:49 -0600
Processing by PublicController#show as HTML
Parameters: {"id"=>"1"}
[1m[35mPage Load (1.0ms)[0m SELECT "pages".* FROM "pages"
[1m[36mPage Load (0.0ms)[0m [1mSELECT "pages".* FROM "pages" WHERE "pages"."id" = 1 LIMIT 1[0m
Rendered public/show.html.erb within layouts/application (24.0ms)
Completed 200 OK in 63ms (Views: 51.0ms | ActiveRecord: 1.0ms)
Started GET "/public/stylesheets/bootstrap.css" for 127.0.0.1 at 2012-03-03 21:14:50 -0600
ActionController::RoutingError (No route matches "/public/stylesheets/bootstrap.css"):
Rendered c:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.0ms)
Started GET "/public/stylesheets/bootstrap-responsive.css" for 127.0.0.1 at 2012-03-03 21:14:50 -0600
ActionController::RoutingError (No route matches "/public/stylesheets/bootstrap-responsive.css"):
Rendered c:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
Started GET "/public/stylesheets/elements.less" for 127.0.0.1 at 2012-03-03 21:14:51 -0600
ActionController::RoutingError (No route matches "/public/stylesheets/elements.less"):
Rendered c:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (3.0ms)
Thanks for having a look
I managed to find my own answer…
The Rails helper stylesheet_link_tag was generating a relation attribute of type “stylesheet” when the Less css files needed a relation of type “stylesheet/less”.
The fix was specifying the relation like this: