This forum is no longer active. Please post your questions to our new community site

problem working with stylesheets

Subscribe to problem working with stylesheets 4 post(s), 2 voice(s)

 
Avatar edgo 2 post(s)

Hello,
I am new with rails. Let me first describe the environment.
I installed rubystack-2.1-0. Created an appliation – labapp. This is how directory tree look like:
/opt/rubystack-2.1-0/labapp/app/controllers with labrooms_controller.rb
/opt/rubystack-2.1-0/labapp/app/models with labroom.rb
/opt/rubystack-2.1-0/labapp/app/views/labrooms with index.html.erb show… etc
/opt/rubystack-2.1-0/labapp/app/views/layouts with labrooms.html.erb
Up to this all usual.
Now in layouts/labrooms.html.erb:

<%= stylesheet_link_tag ‘labrooms’ %>

There is labrooms.css file in
/opt/rubystack-2.1-0/labapp/public/stylesheets/
As I understand all shoul work and css file should be seen.
What happens is I always see
ActionController::RoutingError (No route matches “/stylesheets/labrooms.css” with {:method=>:get}):
I found a lot of references on this problem in the Web, but all of them were related to the Apache reconfiguration. As I understand rubystack works with Mongrel, right? Seems this is some kind of environment problem.
I’m quite stuck and will apreciate help

 
Avatar carlos Administrator 144 post(s)

Hi edgo,

You may try configuring Apache so it takes care of sending any application static files (the ones in public/*) directly. Adding something similar to this in apache configuration:

Alias /appname "${rails_application_dir}/public"
<Directory "${rails_application_dir}/public">
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
# Paths inside public directory that can be served directly by Apache
ProxyPass /appname/stylesheets !
ProxyPass /appname/javascripts !
ProxyPass /appname/images !
# ...
ProxyPass /appname balancer://appcluster
ProxyPassReverse /appname balancer://appcluster
<Proxy balancer://appcluster>
    #  Proxy entries for each of mongrel
    BalancerMember http://127.0.0.1:3001/appname
    BalancerMember http://127.0.0.1:3002/appname
    # ...
</Proxy>

You can find more details in this tutorial where we describe different ways to deploy your application on top of RubyStack using Mongrel, Thin or Passenger.

I hope it helps

 
Avatar edgo 2 post(s)

Hi carlos,
Thanks a lot! It was a good direction. I have configured mongrel cluster and Apache to work as a Proxy. Indeed the error
ActionController::RoutingError (No route matches “/stylesheets/labrooms.css” with {:method=>:get}):
disappeared. However stylesheets still are not applied. But more major problem came up.
Application URL now is http://host:8080/labrooms and it works due to alias in Apache configuration. It opens index.html.erb. In it:

<% @labrooms.each do |labroom| >
<
= link_to labroom.labroom, labroom >
<
= link_to ‘Edit’, edit_labroom_path(labroom) %>
….
Output of rake routes(partial):
(in /opt/rubystack-2.1-0/labapp)
labrooms GET /labrooms(.:format) {:action=>"create", :controller=>"labrooms"}
edit_labroom GET /labrooms/:id/edit(.:format) {:action=>"edit", :controller=>"labrooms"}
labroom GET /labrooms/:id(.:format) {:action=>"show", :controller=>"labrooms"}
So url to “show” should look like /labroom/1, but it looks like /opt/rubystack-2.1-0/labapp/labroom/1 (/opt/rubystack-2.1-0/labapp is RAILS_ROOT) and of course Apache can’t find show page.
May be you can give me a tip here :)

 
Avatar carlos Administrator 144 post(s)

Hi edgo,

The configuration I posted before is intended to make your application run with a prefix. In this case the urls will take the form:

http ://host:8080/appname/:controller/:action/:id.:format

where appname is the prefix used in apache and mongrels configuration.

This is the approach we follow with our modules so you are able to have multiple applications running. In this case, you have to start the mongrels with “—prefix appname” option:

mongrel_rails cluster::configure -e production -p 3001 -N 5  -C ${rails_application_dir}/config/mongrel_cluster.yml --prefix appname

You can find more details about this command in the tutorial I posted before

If you want to have your application in the root directory and have urls like:

http ://host:8080/:controller/:action/:id.:format

Then you should use a different approach:

  1. Mongrels should be started without any prefix option
  2. Instead of using Alias, you should modify DocumentRoot to point to public directory
  3. All prefixes should be removed from previous configuration

After this, you should have something similar to this:

DocumentRoot "${rails_application_dir}/public"
<Directory "${rails_application_dir}/public">
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>
# Paths inside "public" directory that can be served directly by Apache
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass /images !
# ...
ProxyPass / balancer://appcluster/
ProxyPassReverse / balancer://appcluster/
<Proxy balancer://appcluster/>
    #  Proxy entries for each of mongrel
    BalancerMember http://127.0.0.1:3001
    BalancerMember http://127.0.0.1:3002
    # ...
</Proxy>

Let us know if you find any issues