Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Sunday, March 23, 2008

Ruby on Rails - Using External Asset Hosts

Rails uses the "public" directory on the current host as the default location for static assets (images, CSS, Javascript, etc). Setting up your Rails app to use an external assets server is as simple as adding a single line to a configuration file.

Add the following line to your config/environment.rb file:

ActionController::Base.asset_host = 'http://assets.yourdomain.com'

It's also possible to set a single environment to use an external asset host:

Add the following line to config/environments/production.rb (the most likely spot - this line should already be in this file, but commented out):

config.action_controller.asset_host = 'http://assets.yourdomain.com'

Now this line in my layout

<%= stylesheet_link_tag 'scaffold/base' %>

will translate to http://assets.yourdomain.com/stylesheets/scaffold/base.css

Additional information on setting up multiple asset hosts can be found at:

http://api.rubyonrails.com/classes/ActionView/Helpers/AssetTagHelper.html

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels