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!

Posted in Releases | 37 comments

Comments

  1. jmaziarz on 06 Feb 17:15:

    Am I missing something here?

    $ gem list rubygems

    • LOCAL GEMS *

    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>

  2. sailman on 06 Feb 18:01:

    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>

  3. Ilya Sabanin on 06 Feb 18:04:

    Remove “source_cache” file from from ruby/gems/1.8

  4. jared on 06 Feb 18:26:

    and also remove “source_cache” from ~/.gem

  5. Ian Zabel on 06 Feb 18:27:

    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

  6. BillSaysThis on 06 Feb 18:50:

    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.

  7. Chad Fowler on 06 Feb 18:53:

    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.

  8. BillSaysThis on 06 Feb 19:15:

    Chad, I had 0.7.1 installed already—isn’t that the latest? It is on th rubyforge page, at least.

  9. jared on 06 Feb 19:27:

    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.

  10. jmaziarz on 06 Feb 19:39:

    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

  11. BillSaysThis on 06 Feb 19:41:

    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’

  12. Ned on 06 Feb 20:12:

    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)

  13. ZKM on 06 Feb 21:27:

    The sqlite adapter in 1.2.2 still creates tables without AUTOINCREMENT

  14. Chad Fowler on 06 Feb 22:38:

    BillSaysThis, even though you have the latest Rake, if you reinstall it, it will fix the warnings.

  15. dudz.josh on 06 Feb 22:49:

    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

  16. Jamieorc on 06 Feb 22:53:

    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.

  17. Dave Myron on 06 Feb 23:03:

    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.

  18. Jamieorc on 06 Feb 23:31:

    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

  19. Carlos Villela on 07 Feb 00:34:

    Thanks Jamieorc, I was having the same problem :)

  20. tj on 07 Feb 05:02:

    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

  21. Donald Piret on 07 Feb 07:55:

    Loving the singular resources, finally a good way to model user login and session in a RESTful way

  22. Jamieorc on 07 Feb 16:50:

    Carlos, glad I helped!

  23. Ned on 07 Feb 17:31:
    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: ...
    • Invoke db:test:prepare
    • Execute test:integration /usr/local/bin/ruby -Ilib:test ”/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb” rake aborted! Test failures /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/tasks/testing.rake:50 /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `call’ /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute’ /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `each’ /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:387:in `execute’ /usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake.rb:357:in `invoke’ ...

    In there another resource you can forward me to?

  24. Ronan on 07 Feb 19:55:

    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

  25. Jeff on 08 Feb 04:51:

    It appears that 1.2.2 is breaking routes in my app, which work in 1.2.1.

    I have routes setup as follows:
    
    map.resources :sites do |site|
      site.resources :posts, :name_prefix => 'site_'
    end
    
    My edit form submits to an update action:
    
    <% form_for(:post, :url => site_posts_path, :html => {:method => :put, :id => 'edit-post'}) do |f| %>
    
    In 1.2.1 I get the form submit yields the expected results:
    
    Processing PostsController#update (for 127.0.0.1 at 2007-02-07 22:42:15) [PUT]
      Session ID: 7521fbd5e9a36f42f29cb7a4294e7863
      Parameters: {"commit"=>"publish", "site_id"=>"2", "post"=>{"title"=>"test", "publish_on(1i)"=>"2007", "publish_on(2i)"=>"2", "story"=>"test", "publish_on(3i)"=>"7", "id"=>"8", "post_type"=>"Article"}, "_method"=>"put", "action"=>"update", "controller"=>"posts"}
      User Columns (0.004084)   SHOW FIELDS FROM users
      User Load (0.000989)   SELECT * FROM users WHERE (users.id = 1) 
      Site Columns (0.004015)   SHOW FIELDS FROM sites
      Site Load (0.001226)   SELECT * FROM sites WHERE (sites.id = 2 AND (sites.user_id = 1)) 
      Post Columns (0.004380)   SHOW FIELDS FROM posts
      Post Load (0.001641)   SELECT * FROM posts WHERE (posts.id = 8 AND (posts.site_id = 2)) 
      Article Columns (0.004726)   SHOW FIELDS FROM posts
      SQL (0.000264)   BEGIN
      Article Update (0.000518)   UPDATE posts SET `created_at` = '2007-02-07 21:09:41', `story` = 'test', `days_comments_open` = 0, `title` = 'test', `ingredients` = NULL, `post_state_id` = 1, `user_id` = 1, `publish_on` = '2007-02-07', `site_id` = 2, `post_type` = 'Article', `updated_at` = '2007-02-07 22:42:16', `video_url` = NULL, `image_url` = NULL WHERE id = 8
      SQL (0.001052)   COMMIT
    Redirected to http://vhz.dev:3000/sites/2/posts/8
    Completed in 0.14097 (7 reqs/sec) | DB: 0.02289 (16%) | 302 Found [http://vhz.dev/sites/2/posts]
    
    In 1.2.2, Rails seems to be mangling the action, id and controller parameters and calling up a bad route on form submit:
    
    Processing SitesController#2 (for 127.0.0.1 at 2007-02-07 21:12:34) [PUT]
      Session ID: 7521fbd5e9a36f42f29cb7a4294e7863
      Parameters: {"commit"=>"publish", "post"=>{"title"=>"test", "publish_on(1i)"=>"2007", "publish_on(2i)"=>"2", "story"=>"test", "publish_on(3i)"=>"7", "id"=>"8", "post_type"=>"Article"}, "_method"=>"put", <strong>"action"=>"2", "id"=>"posts", "controller"=>"sites"</strong>}
      User Columns (0.003988)   SHOW FIELDS FROM users
      User Load (0.000982)   SELECT * FROM users WHERE (users.id = 1) 
      Site Columns (0.004179)   SHOW FIELDS FROM sites
      Site Load (0.001241)   SELECT * FROM sites WHERE (sites.id = 0 AND (sites.user_id = 1)) 
    
    ActiveRecord::RecordNotFound (Couldn't find Site with ID=posts AND (sites.user_id = 1)):
    
  26. dharana on 09 Feb 16:57:

    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.

  27. dharana on 09 Feb 17:10:

    Apparently its not the only thing broken:

    http://dev.rubyonrails.org/ticket/7372

    I love rails but I will wait for a working release.

  28. alfred toh on 09 Feb 19:33:

    Any idea this would still be a recommended upgrade from 1.2.1? Comments from dharana seems to hint not to.

  29. I r troll on 10 Feb 00:45:

    I love you dharana, plz have troll sex with me.

  30. dharana on 10 Feb 02:44:

    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.

  31. Jeff on 10 Feb 14:17:

    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.

  32. Meekish on 16 Feb 20:39:

    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!

  33. Carl Youngblood on 20 Feb 08:32:

    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.

  34. Raker on 24 Feb 02:21:

    How do you update rake itself?

  35. Big Momma on 24 Feb 02:29:

    sudo gem update rake

  36. Mauro Cicio on 03 Mar 08:46:

    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?

  37. Tim Harper on 06 Mar 01:19:

    Thanks Jamieorc, I was having the same problem too!