Following my previous blog, I happen to work on another rails upgrade at the beginning of my new project. This time rails 3.0.7 to 3.1. I though, I should document these steps, as it might help myself or someone else in future.
I googled and found a good discussion on stack-overflow. As Forrest Ye gave the right answer, I began the migration step by step, as it is written:
"Edit Gemfile, change Rails gem version
Also adds new gems introduced in 3.1.0
I found few conflicts and before accepting them, I tried to understand:
1. config/application.rb:
I paid attention to:
2. config/environments/development.rb:
I googled and found a good discussion on stack-overflow. As Forrest Ye gave the right answer, I began the migration step by step, as it is written:
"Edit Gemfile, change Rails gem version
gem 'rails', '3.1.0'
Also adds new gems introduced in 3.1.0
group :assets dorun
gem 'sass-rails', "~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
gem 'jquery-rails'
bundle update railsThen run rake rails:update and resolve conflicts."
I found few conflicts and before accepting them, I tried to understand:
1. config/application.rb:
I paid attention to:
config.assets.enabled = truewhich means you are enabling assets pipe-lining which is one of the feature of rails 3.1, I accepted the changes.
config.assets.version = '1.0'
2. config/environments/development.rb:
config.action_view.debug_rjs = truewhich has been deprecated, so this line should be deleted, if you are using rjs in views, debugging is not supported now.
config.assets.compress = falsewhich means assets compression is off in development, I accepted the changes.
config.assets.debug = true
it means, you can see the assets being loaded in logs. I accepted this change.
3. config/environments/production.rb
I saw again configuration related to asset pipeline:
Once this is done, move all assets from public/images, public/javascripts, public/stylesheets to app/assets/ directory. Again, you have to make sure, that you
Include css/javascript links in your layout file like this
config.assets.compress = trueSimply, accept these changes.
config.assets.compile = false
config.assets.digest = true
Once this is done, move all assets from public/images, public/javascripts, public/stylesheets to app/assets/ directory. Again, you have to make sure, that you
Include css/javascript links in your layout file like this
<%= stylesheet_link_tag "application" %>Again, it is important to understand the behavior of asset pipeline and how it works. For example, in application.js file, you will have:
<%= javascript_include_tag "application" %>
//= require_tree .
that means, all the files from assets/javascripts directory will be loaded automatically, as application is being loaded, in hierarchical format. If you do need js files in sequence, mention that above this line, e.g.:
//= require jquery
//= require jquery_ujs
//= require highcharts
//= require_tree .
Similarly you have application.css file, which will load assets in hierarchy, so override it if needed.
One important thing I noticed is about images, which are embedded in stylesheets. I had stylesheet.css as:
/*So, after moving images to app/assets/images directory, I have to remove the relative path of the image:
*= require_self
*= require_tree .
*/
#header { height:20px; }
body {background-image:url(../images/mainBack.png) !important; background-repeat:repeat-x;}
body {background-image:url(mainBack.png) !important; background-repeat:repeat-x;}
Similarly for all other styles and that is it!
2 comments:
Thanks Gourav!!
I am trying to precompile my assets from the app directory for deploying in Heroku..any idea why it is failing?$ RAILS_ENV=production bundle exec rake assets:precompile
sh.exe": /c/RhoStudio/ruby/bin/bundle: C:/Android/RhoSync/ruby/bin/ruby.exe^M: b
ad interpreter: No such file or directory
Hi Doel,
Not sure if you have tried re-installing the rake gem, re-installing should work in your case.
Post a Comment