Upgrading from Rails 3 to Rails 3.1 [closed] - ruby-on-rails

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
How do you upgrade from Rails 3 to Rails 3.1 beta?

This is what worked for me when updating an existing rails 3.0.8 project. Your mileage may vary...
Update the rails version specified in my Gemfile to use the latest release candidate:
gem 'rails', '3.1.0.rc4’
Update the bundle:
bundle update
Then update the project with the rake command:
rake rails:update
After cherry picking though the change conflicts I ran all my tests and they passed (yay!). I restarted the server and everything seems good so far.
However, this is not using the new asset pipeline yet. By that I mean the javascript and css (or sass) files are still being handled in the pre-pipeline manner. As I understand it, this is a perfectly viable option. But of course, I want the new goodness, so I believe the next steps are to include and additional gems (e.g. coffeescript, sass, uglifier, etc) and then to migrate the old files to the app/assets directory.
I found some details about that are here:
http://blog.nodeta.com/2011/06/14/rails-3-1-asset-pipeline-in-the-real-world/
Hope that was helpful.

I just upgraded from 3.0 to 3.1 by changing my Gemfile to:
gem 'rails', '3.1.0.rc1'
gem 'sqlite3'
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
I also commented out the following line below in config/environments/development.rb
# config.action_view.debug_rjs = true
Finally, make sure you enable the asset pipeline in config/application.rb
config.assets.enabled = true
I'm not sure if you've already read the release notes http://weblog.rubyonrails.org/2011/4/21/jquery-new-default

Upgrading Rails
Update: be cautious of using your system rake, as rake has been upgraded.
bundle exec rake
ensures you'll be using the correct rake for a given rails project (source)
I suggest beginning with a fresh app, then copying in your specific app information while shifting your resources into the new asset/sprockets format.
An example
While converting an older rails 2.3.4
app to 3.0 I crashed and burned while
changing one file at a time over
within the project. Needless to say
that was a flawed strategy, but I did
learn a little along the way. I ended
up skipping 3.0 and moving to 3.1beta1
with a fresh app, and copied my app
and public folders in after getting
the migrations right. That move had a
couple of outstanding issues, the most
important being that I didn’t use
rails edge for creating the new app
(thanks for the tip RubyInside).
First snag the latest rails into an
easy to reference location:
cd ~/goodtimes
git clone
https://github.com/rails/rails.git
My path includes a ~/Desktop/Dropbox/
so my code is available everywhere.
Then refer to that rails exec for
building a new app:
~/goodtimes/rails/bin/rails new bacon --edge
Depending on the complexity of your database, you'll either want to create new migrations using the change syntax or leave them be:
class CreatePosts < ActiveRecord::Migration
def change
create_table :posts do |t|
t.string :title
t.text :body
t.timestamps
end
end
end
I had an issue deploying to Heroku, but theRubyRacer gem helped square that away. Here's an example of a simple Gem file:
source 'http://rubygems.org'
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
# Asset template engines
gem 'sass'
gem 'coffee-script'
gem 'uglifier'
gem 'jquery-rails'
gem 'pg'
gem 'therubyracer-heroku', '0.8.1.pre3', :platforms => :ruby
# Use unicorn as the web server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
group :test do
# Pretty printed test output
gem 'turn', :require => false
end
I suspect there will be community utilities to help you automate migration from older versions of Rails to the --edge.
References:
How to Play with Rails 3.1, CoffeeScript and All That Jazz Right Now
The Four Horsemen of Rails 3.1beta, Coffee-Script, jQuery, SCSS and Assets
Rails 3.1beta deployed to Heroku from your iPhone
Reversible Migrations

I recommend updating your Gemfile to use edge rails. For example:
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'arel', :git => 'git://github.com/rails/arel.git'
gem 'rack', :git => 'git://github.com/rack/rack.git'
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sqlite3'
# Asset template engines
gem 'sass', '~> 3.1.0.alpha'
gem 'coffee-script'
gem 'uglifier'
You can read more here http://pogodan.com/blog/2011/04/24/easy-edge-rails.

If i understood your question correctly this is how:
gem install rails --pre

Related

Ignore group in Rails Gemfile

I have the puma gem in my Rails 4.1.8 Gemfile because I want to use it as the default webserver in all environments. That works fine.
# Gemfile
gem "puma"
In development I am using mailcatcher which means that I'd like to include it as a dependency in my Gemfile.
# Gemfile
group :development do
gem "mailcatcher"
end
This causes the default webserver to be set to thin. This appears to be an unintended consequence of mailcatcher, but it brings up a specific question. Can I create a group that bundler obeys to install Gems, but that Rails ignores? I tried something like this but Rails is still loading the contained gems.
# Gemfile
group :mailcatcher do
gem "mailcatcher"
end
You can alias rails s command... For example export alias rs="rails server puma" and now rs will start puma. This way you are free to use any webserver you want )
If you want to make it really default you can add something like this
require 'rack/handler'
Rack::Handler::WEBrick = Rack::Handler.get(:puma)
to the rails script.
I don't know if this will work or not, but what about:
gem "mailcatcher", :require => false
Ref: Bundler: What does :require => false in a Gemfile mean?
Mailcatcher specifically states to not put it in your Gemfile.
Please don't put mailcatcher into your Gemfile. It will conflict with your applications gems at some point.
Instead, pop a note in your README stating you use mailcatcher. Simply run gem install mailcatcher then mailcatcher to get started.

Error launching Rails server: undefined method 'configure'

I'm new to rails and working through Hartl's tutorial. Everything was fine until I tried to do the tutorial a second time and created another project trying to use the latest version of rails. When I try to load the rails server from the app folder I get the following error.
$ rails s
=> Booting WEBrick
=> Rails 4.0.4 application starting in development on
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/Users/sierra/Desktop/sample_app_2/config/environments/development.rb:1:in
`<top (required)>': undefined method `configure' for
#<SampleApp2::Application:0x00000101a74610> (NoMethodError)
My Gemfile is directly from the Hartl tutorial:
source 'https://rubygems.org'
ruby '2.1.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
I resolved it by doing following step.
Step 1: go to Project_Root_Directory/config/environment/development.rb
Change this line
Rails.application.configure do
To
Your_Rails_Application_Folder_name::Application.configure do
For example my rails project folder name is 'Spree_demo' so Your_Rails_Application_Folder_name in the following line:
Your_Rails_Application_Folder_name::Application.configure do
will be replaced as
SpreeDemo::Application.configure do
Note: See underscore in your application folder name it gets removed.
Hope it works for you guys.
First set Ruby version before Rails new
I had the same problem and I tried the answer given and it had no impact.
I even tried changing the name to get rid of the underscore, and it had no impact.
The problem is that you did this:
$ rails new app_name
But your ruby version was probably 2.1.1 or something else. You want to do:
$ rvm 2.0.0
BEFORE you run the new app, and then when you set 2.0.0 in your Gemfile (as Hartl recommends) it falls into place.
I don't know WHY this works, and I hope someone will shed light on it, but I can tell you that this worked better than the answer that is currently in the lead.
That happened to me too. The problem was that I used one version of Rails to create the project. Then I changed the Gemfile to use another version of Rails and the system was using it to scaffold or run the server. Newbie problem!
Using the same version consistently should solve the problem. :-)
I posted a (probably way too long) answer in a similar question: rails - NoMethodError: undefined method `configure' for FirstApp. This thread actually started me on the way to my eventual solution, so I thought I'd post here as well just in case it's helpful to anyone else.
From what I can tell, the problem occurs when the app/config/initializers/development.rb (and production.rb) files are generated for a new project using some newer versions of Rails (I'm not sure in which version it started, I only tested Rails 4.1.4). Mr. Hartl uses Rails 4.0.8 for his tutorial, and that's the highest version I tested in which the new syntax doesn't occur.
In Rails 4.1.4, and maybe some other versions after 4.0.8, the first line in those files is generated as Rails.application.configure.do rather than, using a project called sample_app as an example, SampleApp::Application.configure.do as in 4.0.8.
I'm new to Rails so I don't know why this syntax changed in newer versions. I'm assuming it's intentional and somehow better than the old way. Most likely, Mr. Hartl will take it in to account in future editions of his tutorial that are updated for versions of Rails which include this change.
Until then, see my other answer in the question I mentioned above for a more thorough explanation of how I got around it on Windows 7, but the tl;dr of it is:
Make sure you're using the version of Rails specified for the tutorial (4.0.8) in your local repository/root development directory before you create your new project. Updating your Gemfile after creating the project is still important, but it won't solve this problem if the files themselves were generated with a newer version of Rails. You'll have to go in and edit that line manually in that case, as other users have suggested.
I had this issue when I messed around with my Gemfile. For example I have created the app using rails 4.0.2 or something like that then due to some errors I changed it to 4.1.1 that change cause this exact same problem in both development and production

gem version dilemma with rails 3.1

I want to use ebayapi gem (https://github.com/codyfauser/ebay) with my rails 3.1 application.
If I add the gem in the Gemfile, rails doesn't run.
/Users/ssk/.rvm/gems/ree-1.8.7-2011.03/gems/money-1.7.1/lib/support/cattr_accessor.rb:7:in `cattr_reader': undefined method `id2name' for {:instance_writer=>true}:Hash (NoMethodError)
I removed the ebayapi gem and tried "require 'ebay'" but it said that "no such file to load".
Ebayapi gem works only with money 1.7.1 and I think that conflicts with rails 3.1 (maybe 3.0 as well).
Is there a way to workaround?
Thanks.
Sam
If it's truly incompatible, and you're up to fixing it yourself, then fork the projects in question on github, and update your Gemfile to point to your git repo (or even a local path to make editing a lot easier).
Here's an example:
gem 'money', :path => "~/dev/ruby/gems/money"
# or
gem 'money', :git => "git://github.com/my_account/money.git"
Once you've fixed it, send a pull request to the original project so they can include the fix.

In Rails, why sqlite works without config.gem 'sqlite3-ruby'

With a new Rails 2.3.10 project, the file config/environment.rb has the following line commented out:
# config.gem "sqlite3-ruby", :lib => "sqlite3"
but for some reason, I tried a scaffold foo, and start the rails server, and the app is running.
I thought the requirement is, every gem the app needs, it has to be listed in config/environment.rb?
In Rails 2.3, it's enough to have the gem installed on your system for you to use it.
In Rails 3, you must have the gem listed in your Gemfile and installed via bundler to use the gem.

How do I setup and utilize Shoulda, Factory_Girl, and Cucumber in a Rails 3 application?

I'm able to get my Gemfile how I like it:
# Gemfile
source "http://gemcutter.org"
gem "rails", :git => "git://github.com/rails/rails.git"
git "git://github.com/rails/arel.git"
git "git://github.com/rails/rack.git"
gem "sqlite3-ruby"
group :test do
gem "shoulda", :git => "git://github.com/thoughtbot/shoulda.git", :branch => "rails3"
gem "factory_girl", :git => "git://github.com/thoughtbot/factory_girl.git", :branch => "rails3"
gem "capybara"
gem "database_cleaner"
gem "cucumber-rails"
end
Then, of course, bundle install
From here, would someone be able to walk me through the process of generating a Cucumber scenario, creating a Factory, and then using the factory with Shoulda declarations inside a unit test? I've seen bits and pieces of all of these things scattered over blogs but due to the speed at which Rails3 is moving I am having a hard time finding a definitive source and my own forays have been unsuccessful and frustrating. Rather than providing my error messages I was hoping someone could just walk me through a clean-slate approach to show how it all works. This would probably be a good addition to http://guides.rails.info Testing section.
Perhaps the resource could be: bundle exec rails generate scaffold task description:string notes:text project_id:integer due:date complete:boolean only using Cucumber of course.
Thank you so much on behalf of all of us still learning and trying to follow tdd/bdd!

Resources