Rails 1.2.2: SQLite3, gems, singular resources
Posted by David February 06, 2007 @ 04:29 PM
It’s time for another minor update to Rails 1.2. This was primarily prompted by a change in the API for SQLite between version 3.3.7 and 3.3.8+, which left the Rails database adapter for dead by the road side. But with this release and Jamis Buck’s sqlite3-ruby gem at version 1.2.1, we’re back in business on all versions of SQLite3.
Second, we’re now depending on RubyGems 0.9.0 and above. This will fix the deprecation messages for require_gem (the new method is just gem) and will restore rake rails:freeze:gems to working order. So be sure to update to the latest RubyGems before installing. That’s done with “gem update—system”.
Finally, we’ve decided to throw in a few goodies along with the fixes described above and the rest of the bug reparations in this release. Singular resources, for example, allow you to model singleton resources within the scope of the domain. The common example is user.application.com/account. That’s now modeled with:
map.resource :account
...and routes accordingly:
GET /account => AccountController#show
GET /account/new => AccountController#new
GET /account;edit => AccountController#edit
POST /account => AccountController#create
PUT /account => AccountController#update
DELETE /account => AccountController#destroy
Note that the controller is also singular, not plural as is usually the case when using map.resources.
We’ve also brought over the enhancement to :conditions in Active Record that’ll allow you to pass in ranges and get them automatically converted to BETWEEN statements. Like:
Student.find(:all, :conditions => { :grade => 9..12 })
...which then becomes:
"SELECT * FROM students WHERE grade BETWEEN 9 AND 12"
This is a recommended upgrade for everyone running 1.2.x (and a reminder that if you’re not yet on Rails 1.2.x, you won’t be getting bug fixes automatically and have to backport them yourself). It’s a drop-in replacement requiring no changes to applications running 1.2.x.
Enjoy!

Am I missing something here?
$ gem list rubygems
rubygems-update (0.9.2) RubyGems Update GEM
$ gem update sqlite3-ruby Updating installed gems… ERROR: While executing gem … (NoMethodError) undefined method `refresh’ for #<hash:0x14e0a4c>
After upgrading rubygems, RoR install error:
Installing rubygems-0.9.2 ri… Installing rubygems-0.9.2 rdoc…
As of RubyGems 0.8.0, library stubs are no longer needed. Searching $LOAD_PATH for stubs to optionally delete (may take a while)... ...done. No library stubs found.
RubyGems system software updated zsolt-hegedus-computer:~ sailman$ gem install rails—include-dependencies ERROR: While executing gem … (NoMethodError) undefined method `refresh’ for #<hash:0x1074c64>
Remove “source_cache” file from from ruby/gems/1.8
and also remove “source_cache” from ~/.gem
Since I had trouble with the command noted in this post to update gem, here’s the command that worked for me:
gem update—system
Note, that is: gem<space>update<space><hyphen><hyphen>system
I just updated to 1.2.2 after running the “gem update—system” command, and the result seemed as expected. Switching into a project directory I ran “rake rails:update” to bring it in line with the latest and instead I keep getting this message:
Miami-Steve:~/RailsApps/hmvv williamlazar$ rake rails:update /usr/local/bin/rake:17:Warning: require_gem is obsolete. Use gem instead. (in /Users/williamlazar/RailsApps/hmvv) /Users/williamlazar/RailsApps/hmvv/config/boot.rb:29:Warning: require_gem is obsolete. Use gem instead.
If I hand edit boot.rb and re-run the rake, the same error is shown and the file has reverted.
I created a fresh Rails project and boot.rb has the new syntax already.
BillSaysThis: I think the problem is that rake needs to be updated as well. If you start script/console, do you also get the warning? If not, it’s rake doing it.
Chad, I had 0.7.1 installed already—isn’t that the latest? It is on th rubyforge page, at least.
BillSaysThis: 1.Edit your environment.rb to indicate that you’re using rails 1.2.2 2.Then run ‘rake rails:update’
You will still get the error message, but your files will be updated for you.
I reverted to my previous working rubygem version (0.8.11) and tried to reinstall rails:
$ gem install rails—include-dependencies Attempting local installation of ‘rails’ Local gem file not found: rails*.gem Attempting remote installation of ‘rails’ ERROR: While executing gem … (OpenURI::HTTPError) 403 Forbidden
Thanks, Jared, that was the answer.
Next problem… I like to have the Rails docs locally but the rake task is failing:
Miami-Steve:~/RailsApps/hmvv williamlazar$ rake doc:rails (in /Users/williamlazar/RailsApps/hmvv) rake aborted! Don’t know how to build task ‘vendor/rails/railties/CHANGELOG’
I can update the boot.rb file manually or via rake ‘rake rails:update but then rake just fails for me afterwards when used just to run test cases. (Rake 0.7.1)
The sqlite adapter in 1.2.2 still creates tables without AUTOINCREMENT
BillSaysThis, even though you have the latest Rake, if you reinstall it, it will fix the warnings.
I really like that look of the new single resource. However it doesn’t seem to work. Is anyone else getting this problem?
I use to use this to accomplish the same thing with resources but it doesn’t seem to work since some time after revision 6060
Inflector.inflections do |inflect| inflect.uncountable %w( account ) end
Running rake test:units, I’m getting “rake aborted! uninitialized constant ActiveSupport::Deprecation::RAILS_DEFAULT_LOGGER”.
Reverting to 1.2.1 solves the problem. Anyone else seeing this?
Chad: thanks for that—I reinstalled Rake and the warning disappeared for require_gem.
Ouch, sucks that bug 7372 snuck into 1.2.2 (http://dev.rubyonrails.org/ticket/7372). Breaks functional tests that use sessions. 1.2.3 will be coming shortly, methinks.
Turns out the error I got around RAILS_DEFAULT_LOGGER had to do with ActionMailer::Base.server_settings being changed to smtp_settings. The error message wasn’t revealing.
Ryan Daigle has a posting about this: http://ryandaigle.com/articles/2007/1/31/what-s-new-in-edge-rails-actionmailer-base-server_settings-deprecated
Thanks Jamieorc, I was having the same problem :)
Now that sqlite3-ruby has been updated, are there known issues with this setup:
rails 1.1.6 sqlite3-ruby 1.2.1 sqlite 3.3.10
Thanks in advance for any feedback.
-TJ
Loving the singular resources, finally a good way to model user login and session in a RESTful way
Carlos, glad I helped!
I must have something wrong with ‘removing rake’ as I still get the same problem I mentioned. Using rails 1.2.2… I do this: sudo gem uninstall rake sudo gem install rake rake rails:update and that all works fine, but when I run: rake—trace by itself, it fails with the following trace: ...
In there another resource you can forward me to?
Hi, I installed the new version after updating rubygems and so on. My unit tests complained about using ‘require_gem’ so I changed to ‘gem’ as recommended. It really didn’t like that. I get the following error when trying to run my tests:
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:266:in `load_missing_constant’: uninitialized constant ActionController (NameError) from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in `const_missing’ from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:464:in `const_missing’ from /home/ronan/depot/main/rsrc/click/config/environment.rb:33 from /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/initializer.rb:41:in `run’ from /home/ronan/depot/main/rsrc/click/config/environment.rb:15 from ./lib/../test_helper.rb:12 from ./lib/security_test.rb:11 from test_all.rb:17 from test_all.rb:15
Looks like I’ll be putting up with the deprecation warning for a while :-) Thanks for all the great work on rails. Ronan
It appears that 1.2.2 is breaking routes in my app, which work in 1.2.1.
I have routes setup as follows: My edit form submits to an update action: In 1.2.1 I get the form submit yields the expected results: In 1.2.2, Rails seems to be mangling the action, id and controller parameters and calling up a bad route on form submit:Drop-in replacement? Sure
In 1.2.1 doing
User.find_by_login(:dharana)
returns the user with dharana as his column name.
In 1.2.2 doing
User.find_by_login(:dharana)
returns nil so no, it’s not a drop-in replacement.
Apparently its not the only thing broken:
http://dev.rubyonrails.org/ticket/7372
I love rails but I will wait for a working release.
Any idea this would still be a recommended upgrade from 1.2.1? Comments from dharana seems to hint not to.
I love you dharana, plz have troll sex with me.
alfred: You should have a comprehensive battery of tests. I started late adding tests to my rails applications but I have enough. After updating to rails 1.2.2 I did a rake:test and from a total of 820 tests there were 45 failling so you have an idea of how many things broke in my case.
I r troll: As I understood from the announcement the only thing that changed from 1.2.1 to 1.2.2 were “SQLite3, gems, singular resources”. Because there was no detailed list of things fixed/changed (something that would be very useful and that is done in other similar projects like php and python for exmaple) I supposed they didn’t change behaviour from previous version and it really was a drop-in replacement. But at least I had tests and I didn’t update my production websites with 1.2.2.
With respect to #25 above, I failed to run
rake rails:update. After running update, Rails 1.2.2 reported that I had certain malformed named routes in my app. So in my case, Rails 1.2.1 let me get away with mistakes that 1.2.2 catches.I was banging my head against the table trying to figure out how I was going to get around the SQLite bug. Thank you Jamis. You are one swell chap—and hello from Twin Falls, ID!
I’m still getting the same NULL and single-quote errors after installing rails 1.2.2 and updating my app. I’m running sqlite 3.3.13 on OS X Tiger PPC.
How do you update rake itself?
sudo gem update rake
It seems that the single resource has introduced an issue of with uncountable.
I tried:
./script/generate scaffold_resource fish name:string
and hitting ‘new’ got me the following: fish_url failed to generate from {:controller=>”fish”, :action=>”show”} – you may have ambiguous routes, or you may need to supply additional parameters for this route. content_url has the following required parameters: [“fish”, :id] – are they all satisifed?
Thanks Jamieorc, I was having the same problem too!