Tuesday, September 6, 2011

Getting error "ArgumentError: wrong number of arguments (3 for 2)" for mysql2_adapter

In one of my application I am using Ruby 1.9.2, mysql2 gem, Rails 3.0.6.

While upgrading to Rails 3.1, getting following error throughout the application. When I ran command on console, then also getting same error:

ruby-1.9.2-p290 :003 > c = Cuisine.all
ArgumentError: wrong number of arguments (3 for 2)
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/mysql2-0.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:585:in `select'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/database_statements.rb:18:in `select_all'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/query_cache.rb:63:in `select_all'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:470:in `find_by_sql'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation.rb:111:in `to_a'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/relation/finder_methods.rb:155:in `all'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/base.rb:441:in `all'
    from (irb):3
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:45:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands/console.rb:8:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Solution to fix the problem:

In Gemfile, replace 'mysql2' line with

       gem 'mysql2', '>= 0.3'

and install mysql2 greater than '0.3' version, in my case it is ' mysql2 (0.3.6) ' and it will work :)


NOTE: as of Rails 0.3.0, and ActiveRecord 3.1 - the ActiveRecord adapter has been pulled out of mysql2 gem and into ActiveRecord itself. If you need to use mysql2 with Rails versions < 3.1 make sure and specify gem "mysql2", "~> 0.2.7" in your Gemfile

And for Rails version 3.1 or above use  gem 'mysql2', '>= 0.3'

Sunday, September 4, 2011

Rails 3.1.0 has been released!

Rails 3.1.0 has been released!:
Hi everybody!
It's been 3 Months since RailsConf, so I think it's time we released Rails 3.1.0. So, here it is! I've released Rails 3.1.0!

CHANGES

For a much more attractive and easy to read list of changes, please check out the awesome Rails 3.1.0 Release Notes on the Rails Guides site. For a less attractive list of changes, please continue to read!

Here are some highlights of the major changes in Rails 3.1.0:

ActionPack


  • ActionPack has been updated to include the new asset pipeline. Please see the rails guides on the asset pipeline.
  • Streaming response support has been added. This feature allows you to stream templates to the user before processing has actually finished. See the Rails Guides, or documentation in ActionController::Metal::Streaming for more information. Middleware have been refactored to support this feature.
  • RJS has been extracted to a gem.

ActiveModel

  • attr_accessible and friends now accepts :as as option to specify a role
  • Added ActiveModel::SecurePassword to encapsulate dead-simple password usage with BCrypt encryption and salting.

ActiveRecord

  • Prepared statement caches have been integrated. ActiveRecord::Base#create and simple finders will use a prepared statement and cache for more performant inserts and selects.
  • Associations have been refactored for greater simplicity and maintainability.
  • default_scope can take any object that responds to call.
  • PostgreSQL adapter only supports PostgreSQL version 8.2 and higher.
  • Migrations use instance methods rather than class methods. Rather than defining a self.up method, you should define an instance method up.
  • Migrations are reversible. When a new migration is generated, the migration will contain one method called change. Database changes made in this method will automatically know how to reverse themselves. For more information, see the documentation for ActiveRecord::Migration and ActiveRecord::Migration::CommandRecorder.
  • When a model is generated, add_index is added by default for belongs_to or references columns.

ActiveResource

  • The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set self.format = :xml in the class.

ActiveSupport

  • ActiveSupport::BufferedLogger set log encoding to BINARY, but still use text mode to output portable newlines.
  • Add Object#in? to test if an object is included in another object.
  • ActiveSupport::Dependencies::ClassCache class has been introduced for holding references to reloadable classes.
  • Added weeks_ago and prev_week to Date/DateTime/Time.
  • JSON decoding now uses the multi_json gem which also vendors a json engine called OkJson. The yaml backend has been removed in favor of OkJson as a default engine for 1.8.x, while the built in 1.9.x json implementation will be used by default.

Railties

  • The default database schema file is written as UTF-8.
  • Rack::Sendfile middleware is used only if x_sendfile_header is present.
  • Add alias r for rails runner.
  • jQuery is the new default JavaScript library.
  • Added config.force_ssl configuration which loads Rack::SSL middleware and force all requests to be under HTTPS protocol

For more info

For a more detailed list of changes, please see each of the CHANGELOG files checked in to the Rails repository on github.
For an even more detailed list of changes, please see the commit list between Rails 3.0.10 and 3.1.0.

The End

I am personally very proud of this release. I want to say thank you to the people testing our release candidates, the people submitting patches and sending in bug reports. I think that Rails 3.1.0 is the best release of Rails to date, and we could not have done it without you.
Please continue to create amazing things with this framework!

SHA-1

  • b68f74ced662145a4139409edf3c51db1159ead8 actionmailer-3.1.0.gem
  • 136474f270677ae75ad0f9599d26e89cf1d4bc7b actionpack-3.1.0.gem
  • e6b68453c08bb0da52ed1d422ba2f87a5e3aa794 activemodel-3.1.0.gem
  • dfbae15c0d395304812c22fbf18aa9daadbe20b4 activerecord-3.1.0.gem
  • 3f1f547e500d1ffc1f7c3ee4ab9eb1526157a870 activeresource-3.1.0.gem
  • f21627c2f429abfa8685d2147fadab6704c13869 activesupport-3.1.0.gem
  • 21c6592189fb358a066846754a8f7ce7a238fca6 rails-3.1.0.gem
  • 79cfa1eca232de9a45453829287e4438089b7955 railties-3.1.0.gem
<3 <3 <3

'Invalid date' error with Ruby 1.9.2

In one of my Rails 3.0 application, when migrated to Ruby 1.9.2, I am getting "invalid date" error sometimes.
Here is the detail error report:

invalid date
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/date.rb:809:in `civil'
/Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/activesupport-3.0.5/lib/active_support/core_ext/string/conversions.rb:44:in `to_date'
/Users/ror/projects/restaurant/lib/tasks/import_csv.rake:529:in `block (4 levels) in <top (required)>'
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/csv.rb:1768:in `each'
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/csv.rb:1202:in `block in foreach'
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/csv.rb:1340:in `open'
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/csv.rb:1201:in `foreach'
/Users/ror/projects/restaurant/lib/tasks/import_csv.rake:513:in `block (3 levels) in <top (required)>'
/Users/ror/projects/restaurant/lib/tasks/import_csv.rake:504:in `each'
/Users/ror/projects/restaurant/lib/tasks/import_csv.rake:504:in `block (2 levels) in <top (required)>'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:205:in `call'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:205:in `block in execute'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:200:in `each'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:200:in `execute'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/task.rb:144:in `invoke'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:112:in `invoke_task'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:90:in `block (2 levels) in top_level'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:90:in `each'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:90:in `block in top_level'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:84:in `top_level'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:62:in `block in run'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:129:in `standard_exception_handling'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/lib/rake/application.rb:59:in `run'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/gems/rake-0.9.2/bin/rake:32:in `<top (required)>'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `load'
/Users/ror/.rvm/gems/ruby-1.9.2-p290/bin/rake:19:in `<main>'
Tasks: TOP => import:csv

Some Observation
ruby-1.9.2-p290 :030 > a = '18/06/2011'
 => "18/06/2011"
ruby-1.9.2-p290 :031 > Date.parse(a)
 => Sat, 18 Jun 2011
ruby-1.9.2-p290 :032 > a = '06/18/2011'
 => "06/18/2011"
ruby-1.9.2-p290 :033 > Date.parse(a)
ArgumentError: invalid date
    from /Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/date.rb:1022:in `new_by_frags'
    from /Users/ror/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/date.rb:1066:in `parse'
    from (irb):33
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:44:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.0.5/lib/rails/commands/console.rb:8:in `start'
    from /Users/ror/projects/restaurant/highline/ruby/1.9.1/gems/railties-3.0.5/lib/rails/commands.rb:23:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

Conclusion
Ruby 1.9.2 accepts date format "dd/mm/yyyy" not "mm/dd/yyyy"

Getting error 'Could not update iceauthority file' in ubuntu

After logging in to an Ubuntu an ICEauthority error appeared. 

Solution
Press Ctrl-Alt-F1 to get a console. There, I hit Enter to get a login prompt. I logged in with my username and password, and this gave me a regular command prompt. After trying several failed commands, I found the following command on Ubuntuforums.org that helped me to login successfully.

Open a terminal and enter the following command:
sudo chown -R user:user /home/user/.*

Replace user with your username. For example, My username is 'ritesh' so I typed command:
 

sudo chown -R ritesh:ritesh /home/ritesh/.*
After issuing the command, log out and log back in and Ubuntu will be back to normal GUI screen. This error came because of sftp. I installed sftp and assigned my username to use sftp that caused this error to occur. 


Related Links:
- http://ubuntuforums.org/showthread.php?t=1081730&highlight=ICEAuthority&page=2