No implicit conversion of nil into string Ruby Rails - ruby-on-rails-3

I have some code that accesses an MLS listing service and downloads pictures into AWS. I am getting the error on MLS login. I'm on ruby 2.2.2p95 and rails 3.2.22.
My code:
AWS::S3::Base.establish_connection!(
:access_key_id => ACCESS_KEY_ID,
:secret_access_key => SECRET_ACCESS_KEY
)
puts 'connected to AWS'
client = Rets::Client.new({
login_url: LOGIN_URL,
username: LOGIN,
password: PASSWORD,
version: VERSION
})
begin
client.login
# rescue => e
# puts 'Error: ' + e.message
# exit!
end
The error:
➜ LiveByTransit git:(master) ✗ rake update_pics --trace
** Invoke update_pics (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute update_pics
66
connected to AWS
rake aborted!
TypeError: no implicit conversion of nil into String
/home/nitrous/code/LiveByTransit/.bundle/gems/nokogiri-1.6.6.3/lib/nokogiri/xml/document.rb:55:in `read_memory'
/home/nitrous/code/LiveByTransit/.bundle/gems/nokogiri-1.6.6.3/lib/nokogiri/xml/document.rb:55:in `parse'
/home/nitrous/code/LiveByTransit/.bundle/gems/nokogiri-1.6.6.3/lib/nokogiri/xml.rb:64:in `parse'
/home/nitrous/code/LiveByTransit/.bundle/gems/rets-0.9.0/lib/rets/parser/error_checker.rb:17:in `check'
/home/nitrous/code/LiveByTransit/.bundle/gems/rets-0.9.0/lib/rets/http_client.rb:20:in `http_get'
/home/nitrous/code/LiveByTransit/.bundle/gems/rets-0.9.0/lib/rets/client.rb:344:in `http_get'
/home/nitrous/code/LiveByTransit/.bundle/gems/rets-0.9.0/lib/rets/client.rb:63:in `login'
/home/nitrous/code/LiveByTransit/lib/tasks/update_pics.rake:45:in `block in <top (required)>'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/usr/local/opt/rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
.bundle/binstubs/rake:16:in `load'
.bundle/binstubs/rake:16:in `<main>'
Tasks: TOP => update_pics
➜ LiveByTransit git:(master) ✗ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
➜ LiveByTransit git:(master) ✗ rails -v
Rails 3.2.22
In my code above, you'll see I commented out the error rescue. If I comment back in, the error looks like this:
➜ LiveByTransit git:(master) ✗ rake update_pics --trace
** Invoke update_pics (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute update_pics
66
connected to AWS
Error: no implicit conversion of nil into String
➜ LiveByTransit git:(master) ✗
I've tried this suggestion with no change.

Related

'rake db:migrate' is not working correctly. Not creating tables in my simple_cms in my model

Here is what I did:
1. rails generate migration DoNothingYet
invoke active_record
20160919195736_do_nothing_yet.rb
rails generate model User
invoke active_record
create db/migrate/20160919201440_create_users.rb
create app/models/user.rb
invoke test_unit
create test/models/user_test.rb
create test/fixtures/users.yml
Here's the two files I created and edited:
class DoNothingYet < ActiveRecord::Migration
def up
end
def down
end
end
class CreateUsers < ActiveRecord::Migration
def up
`create_table :users do |t|`
`t.column "first_name", :string, :limit => 25`
`t.string "last_name", :limit => 50`
t.string "email", :default => "", :null => false
t.string "password", :limit => 40
#t.dateime "created_at"
#t.datetime "updated_at"
t.timestamps
end
end
def down
drop_table :users
end
end
When I run: rake db:migrate
It does not return anything. When I run rake db:migrate --trace
I get back:
Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:schema:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:schema:dump
When I log in mysql to my simple_cms_development database via my Username- simple_cms.
I try SHOW TABLES;
No tables appeared.
When I run rake db:schema:load --trace this is what I get:
JohnMicttesMBP5:simple_cms john-michaelnalettenalette$ rake db:schema:load --trace
** Invoke db:schema:load (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:schema:load
-- create_table("users", {:force=>:cascade})
-> 0.1929s
-- initialize_schema_migrations_table()
-> 0.1518s
-- create_table("users", {:force=>:cascade})
rake aborted!
Mysql2::Error: Access denied for user 'simple_cms'#'localhost' to database 'test'
/Users/john-michaelnalettenalette/simple_cms/vendor/bundle/gems/mysql2- 0.3.21/lib/mysql2/client.rb:70:in `connect'
/Users/john-michaelnalettenalette/simple_cms/vendor/bundle/gems/mysql2-0.3.21/lib/mysql2/client.rb:70:in `initialize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.2.2/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `mysql2_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:438 :in `new_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:448 :in `checkout_new_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:422 :in `acquire_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:349 :in `block in checkout'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:348 :in `checkout'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:263 :in `block in connection'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:262 :in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:567 :in `retrieve_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/connection_handling.rb:87:in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:646:in `connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-c 4.2.2/lib/active_record/migration.rb:661:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:632:in `block in say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/b enchmark.rb:281:in `measure'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:632:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/migration.rb:652:in `method_missing'
/Users/john-michaelnalettenalette/simple_cms/db/schema.rb:16:in `block in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:41:in `instance_eval'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:41:in `define'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/schema.rb:61:in `define'
/Users/john-michaelnalettenalette/simple_cms/db/schema.rb:14:in `<top (required)>'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/Library/Ruby/Gems/2.0.0/gems/activesupport- 4.2.2/lib/active_support/dependencies.rb:268:in `load'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:218:in `load_schema_for'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:235:in `block in load_schema_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:275:in `block in each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:274:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:274:in `each_current_configuration'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/tasks/database_tasks.rb:234:in `load_schema_current'
/Library/Ruby/Gems/2.0.0/gems/activerecord- 4.2.2/lib/active_record/railties/databases.rake:244:in `block (3 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `call'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/m onitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/rake- 11.2.2/lib/rake/application.rb:152:in `invoke_task'
/Library/Ruby/Gems/2.0.0/gems/rake- 11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/usr/bin/rake:37:in `<main>'
Tasks: TOP => db:schema:load
Any suggestions would be appreciated?
#John-Michael Nalette Have you checked whether the password in the database.yml is correct for the database simple_cms and also if your user has the login to the database.

ruby on rails query on jsonb field does not work

I have a table in the PostgreSQL 9.5 with jsonb column called segmented_data and I have a record with some data in this field
ProjectKeyword.first
=> #<ProjectKeyword:0x007fa83a17e7f8 id: 2201, project_id: 79, keyword_id: 2201, segmented_data: {"keyword_value"=>"land for sale", "dimension_value"=>{"Property type"=>"Land"}}>
How I can find this record in the database by value of one of the keyw of segmented_data?
I have tried:
ProjectKeyword.where("segmented_data ->> 'keyword_value' = 'land for sale'").first
=> nil
ProjectKeyword.where('segmented_data #> ?', {keyword_value: 'land for sale'}.to_json).first
=> nil
ProjectKeyword.where('segmented_data #> ? ', '{"keyword_value":"land for sale"}' ).first
=> nil
What am I doing wrong in these queryes?
EDITED
My Model
class ProjectKeyword < ApplicationRecord
serialize :segmented_data, JSON
belongs_to :project
belongs_to :keyword
has_many :project_keyword_dimensions
has_many :dimensions, through: :project_keyword_dimensions
validates :project_id, :keyword_id, presence: true
end
Migration
class AddSegemtnedDataToProjectKeywords < ActiveRecord::Migration[5.0]
def change
add_column :project_keywords, :segmented_data, :jsonb, default: '{}'
add_index :project_keywords, :segmented_data, using: :gin
end
end
EDITED
I think I found a possible reason of this problem
My db schema still was not in sql format and I added this line
config.active_record.schema_format = :sql
into application.rb file
But now if i running command
bundle exec rake db:migrate --trace
I get this error
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke environment
** Invoke db:load_config
** Execute db:structure:dump
I, [2016-06-21T08:09:14.083751 #51538] INFO -- : [Rollbar] Scheduling item
I, [2016-06-21T08:09:14.102300 #51538] INFO -- : [Rollbar] Details: https://rollbar.com/instance/uuid?uuid=fgfffgf (only available if report was successful)
rake aborted!
TypeError: no implicit conversion of nil into String
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/postgresql_database_tasks.rb:99:in `system'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/postgresql_database_tasks.rb:99:in `run_cmd'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/postgresql_database_tasks.rb:64:in `structure_dump'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/tasks/database_tasks.rb:207:in `structure_dump'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/railties/databases.rake:292:in `block (3 levels) in <top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/railties/databases.rake:67:in `block (2 levels) in <top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.0.rc1/lib/active_record/railties/databases.rake:59:in `block (2 levels) in <top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:248:in `block in execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `each'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:243:in `execute'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/task.rb:173:in `invoke'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:152:in `invoke_task'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `each'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:108:in `block in top_level'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:117:in `run_with_threads'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:102:in `top_level'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:80:in `block in run'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:178:in `standard_exception_handling'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/lib/rake/application.rb:77:in `run'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/bin/rake:23:in `load'
/Users/atrthur/.rbenv/versions/2.3.1/bin/rake:23:in `<top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in <top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
/Users/atrthur/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `<top (required)>'
/Users/atrthur/.rbenv/versions/2.3.1/bin/bundle:23:in `load'
/Users/atrthur/.rbenv/versions/2.3.1/bin/bundle:23:in `<main>'
Tasks: TOP => db:structure:dump
What is wrong with it? How to fix it?
Solution for this problem was to remove this line
serialize :segmented_data, JSON
from model ProjectKeyword
After this line was removed all queries started to work, only the problem now that the default value of : segmented_data is not the hash anymore, it became a string '{}'
So before you update data in this field I have to assign hash value to this field
project_keyword.segmented_data = {}
project_keyword.save!

Devise Backbone Heroku and require.js on Rails configuration

Ok, so I know I am playing with the big boys and girls here messing with front and backend MVC (even though bbone isn't exactly MVC) for an application, but this is the first real robust application I have ever worked on, and unfortunately being in the academics realm, support isn't there, esp for more cutting edge, so I am thankful in advance.
I have some errors when trying to deploy to Heroku with a Rails (3.2.2) app, and the asset pipeline has been causing problems all the time. Since I am using BBone for the front end, and the [single]page[app] needs to know the paths to images and sounds on load, I had to use this gist to attach the image paths to the App.assets to pass to the application.js file for require.js to start the application being built on the front end.
The problem appears to be that Devise wants: config.assets.initialize_on_precompile = false while require wants: config.assets.initialize_on_precompile = true and Heroku wants in the production.rb file to be: config.assets.compile = true.
The error I am getting is in the gist file assets.js.erb where the call is made to the DB to get all the songs in the Song model, second to last line
App = {};
App.assets = {
// Returns an object containing all of asset pipeline's image paths.
//
// Sample:
//
// {
// avatars/missing_avatar.png: "/assets/avatars/missing_avatar.png"
// chosen-sprite.png: "/assets/chosen-sprite.png"
// circle_green.png: "/assets/circle_green.png"
// circle_orange.png: "/assets/circle_orange.png"
// circle_red.png: "/assets/circle_red.png"
// circle_yellow.png: "/assets/circle_yellow.png"
// document.png: "/assets/document.png"
// }
//
// This hash is because Rails' Asset Pipeline bundles the routes to files
// per user session, then hands that to the user's session browser, for security.
// So we create in Ruby (erb = embedded ruby) a hash of the images to be accessed
// in the JS.
images: {
<% AssetsUtil.images.each do |img| %>
"<%= img %>" : "<%= asset_path(img) %>",
<% end %>
},
// Return a formatted URL for an asset.
//
// Sample:
//
// "/assets/document/png."
//
path: function(name) {
// If the file is in our images object, pull the path from there.
if (this.images && this.images[name]) {
return this.images[name];
}
// Otherwise, create a generic asset path.
return '/assets/' + name;
}
};
// Currently this is ALL the songs in the DB, not just the current_user 's songs
App.songs = {
songs: <%= Song.all.to_json.html_safe %>
};
The full trace error trying to rake assets:precompile as suggested todo before deploying to Heroku is:
** Invoke assets:precompile (first_time)
** Invoke requirejs:precompile:external (first_time)
** Invoke requirejs:test_node (first_time)
** Execute requirejs:test_node
** Execute requirejs:precompile:external
/Users/me/.rvm/rubies/ruby-1.9.3-p362/bin/ruby /Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake requirejs:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke requirejs:precompile:all (first_time)
** Invoke requirejs:precompile:prepare_source (first_time)
** Invoke requirejs:setup (first_time)
** Invoke assets:environment (first_time)
** Invoke requirejs:precompile:disable_js_compressor (first_time)
** Execute requirejs:precompile:disable_js_compressor
** Execute assets:environment
** Execute requirejs:setup
** Invoke requirejs:clean (first_time)
** Invoke requirejs:setup
** Execute requirejs:clean
** Execute requirejs:precompile:prepare_source
rake aborted!
uninitialized constant Song
(in /Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb)
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:48:in `block in singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `instance_eval'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65530:in `singletonclass'
/Users/me/dev/SoundOfFractions/app/assets/javascripts/assets.js.erb:65528:in `__tilt_70168709646800'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:144:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/tilt-1.3.4/lib/tilt/template.rb:77:in `render'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:177:in `block in evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/context.rb:174:in `evaluate'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:241:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:262:in `circular_call_protection'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:240:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `new'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:244:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:89:in `block in build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:88:in `build_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:163:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/index.rb:56:in `find_asset'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:94:in `block (4 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:212:in `block in each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:200:in `block (2 levels) in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:190:in `each_entry'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:198:in `block in each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:197:in `each_file'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/sprockets-2.1.3/lib/sprockets/base.rb:210:in `each_logical_path'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:92:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
Tasks: TOP => requirejs:precompile:all => requirejs:precompile:prepare_source
rake aborted!
Command failed with status (1): [/Users/me/.rvm/rubies/ruby-1.9.3-p362...]
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/actionpack-3.2.2/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362/gems/requirejs-rails-0.9.1/lib/tasks/requirejs-rails_tasks.rake:85:in `block (3 levels) in <top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:187:in `block in invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:185:in `invoke_prerequisites'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:165:in `block in invoke_with_call_chain'
/Users/me/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'
/Users/me/.rvm/gems/ruby-1.9.3-p362#global/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `load'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/rake:19:in `<main>'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `eval'
/Users/me/.rvm/gems/ruby-1.9.3-p362/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile => requirejs:precompile:external
gemfile:
source 'https://rubygems.org'
gem 'rails', '3.2.2'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development, :test do
gem 'railroady'
gem 'sqlite3'
# For linux support
gem 'therubyracer'
end
group :production do
gem 'pg'
gem 'thin'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'uglifier', '>= 1.0.3'
end
# gem "better_errors", ">= 0.2.0", :group => :development
# gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'jquery-rails'
gem 'rails-backbone'
gem "bootstrap-sass", "~> 2.3.0.0"
gem 'requirejs-rails'
gem 'ejs'
gem 'devise'
gem "better_errors", ">= 0.2.0", :group => :development
gem "binding_of_caller", ">= 0.6.8", :group => :development
gem 'color_routes'
gem 'gon'
So where should I start with my configuration to finish deployment?
Potential info:
If you watch how to make custom rake tasks from Railscasts here, the same error occurs when running the custom rake task, and Ryan explains that the task can't access the DB because the custom task needs an => :environment dependency (~4:15 in the movie) to access the User class. Since the precompile can't access the songs model, how could I provide the same or similar dependency to the application.js file?
OTHER info:
To my understanding the way the asset pipeline works is for each session, it bundles the paths (so when you type something like <%= link_to 'Sign in', new_user_path %>, rails defines those paths in the asset pipeline, and serves it to the user. Since Backbone is client side rendering, it needs to know the paths to the images and sounds after the page is handed from the rails server, and the only way to do this that I found was the gist listed above, where it bundles the "assets" to the JS, a similar approach to gem 'gon' that provides global variables to the page. I of course am plying in new grounds, and open to restructuring, but it works in dev mode, so I am trying to figure out production as well.
The Rails Environment is not available to you during heroku asset precompile. As they are made once and not refreshed again tell the next deploy. That being said. You should move your dynamic DB related calls to your views and render the data either via API calls or "bootstraping" the data by writing your Javascript ton a script tag in the dom in json. I normally have window.NAME_OF_APPLICATION.collections.SONGS so they are available to me in a global scope.
Example.
:javascript
window.lineItems = {lineItems: #{ #order.line_items.order("position").to_json( :include => :department).html_safe}, order: #{#order.to_json} }
When Backbone comes online have it call for these items. And initialize a collection for them.
#burningpony's accepted answer above is not entirely correct.
The Rails env is available during heroku asset precompile if you use the labs plugin:
https://devcenter.heroku.com/articles/labs-user-env-compile

rake aborted! undefined method `map' for :name:Symbol

I'm trying to pass arguments to a Rake task and access my model as mentioned in "How to pass command line arguments to a rake task" and "Do rails rake tasks provide access to ActiveRecord models?".
However adding => :environment to this code:
require 'rake'
namespace :genre do
desc "Add a genre"
task :add, :genre_id, :name => :environment do |t, args|
puts args.name
end
end
Gives me this error when I run the task:
rake genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol
(See full trace by running task with --trace)
If I delete => :environment it works just fine.
UPDATE:
TRACE:
rake --trace genre:add['1','Abc']
rake aborted!
undefined method `map' for :name:Symbol
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:254:in `set_arg_names'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:29:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task.rb:310:in `define_task'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:32:in `task'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:5:in `block in <top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/task_manager.rb:207:in `in_namespace'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/dsl_definition.rb:102:in `namespace'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/lib/tasks/genre.rake:3:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `block in load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `each'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/engine.rb:425:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/application.rb:145:in `load_tasks'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/private/var/www/html/someapp.com/subdomains/someapp.heroku.com/someapp/Rakefile:7:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `block in load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `block in run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/user/.rvm/gems/ruby-1.9.2-p318/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `load'
/Users/user/.rvm/gems/ruby-1.9.2-p318/bin/rake:19:in `<main>'
Looks like your syntax is off. Try:
task :add, [:genre_id, :name] => :environment do |t, args|

rake db:migrate error Don't know how to build task 'rails_env'

I am getting am error when running rake db:migrate. I have recently added a gem gcm_on_rails after this only I am getting the error.
rake aborted!
Don't know how to build task 'rails_env'
Tasks: TOP => db:migrate => db:load_config
Please help
rake aborted!
Don't know how to build task 'rails_env'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task_manager.rb:49:in `[]'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:60:in `lookup_prerequisite'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:56:in `block in prerequisite_tasks'
/Users/test/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:56:in `collect'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:56:in `prerequisite_tasks'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/.rvm/gems/ruby-1.9.2-p320#global/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/test/.rvm/gems/ruby-1.9.2-p320#global/bin/rake:19:in `load'
/Users/test/.rvm/gems/ruby-1.9.2-p320#global/bin/rake:19:in `<main>'
Tasks: TOP => db:migrate => db:load_config
For using the rake task specified in the gem, I have added the below code in my application controller. This was causing the issue. When I removed it, its working fine.
require 'rake'
Rake::Task.clear
MyAPP::Application.load_tasks