ruby on rails query on jsonb field does not work - sql

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!

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.

rake aborted! ArgumentError: wrong number of arguments (2 for 0..1)

My rails task looks like this:
desc 'Delete records older than 7 days'
task :delete_old_records => :environment do
Post.delete_all('created_at < ?', 7.days.ago)
end
I tried to execute the task using:
rake delete_old_records --trace
and it results to this error:
** Invoke delete_old_records (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute delete_old_records
rake aborted!
ArgumentError: wrong number of arguments (2 for 0..1)
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/relation.rb:453:in `delete_all'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/activerecord-4.2.0/lib/active_record/querying.rb:8:in `delete_all'
/home/codio/workspace/lib/tasks/delete_old_records.rake:3:in `block in <top (required)>'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `call'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:240:in `block in execute'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `each'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:235:in `execute'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:172:in `invoke_with_call_chain'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.rb:165:in `invoke'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:150:in `invoke_task'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `each'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:106:in `block in top_level'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:115:in `run_with_threads'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:100:in `top_level'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:78:in `block in run'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:176:in `standard_exception_handling'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/application.rb:75:in `run'
/home/codio/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in `<top (required)>'
/home/codio/.rbenv/versions/2.1.5/bin/rake:23:in `load'
/home/codio/.rbenv/versions/2.1.5/bin/rake:23:in `<main>'
Does anyone know what I could be doing wrong here? My model looks like:
class Post < ActiveRecord::Base
end
and rake-gem version is rake-10.4.2
Try this
Post.delete_all(['created_at < ?', 7.days.ago])
You could do something like this:
timestamp = Time.now - 7.days
posts = Post.where('created_at < ?', timestamp)
posts.each { |post| post.destroy }
7.days.ago returns a class of ActiveSupport::TimeWithZone.
Time.now - 7.days will return a Time object, which is what you need.
Or you could give this a shot:
posts = Post.where('created_at < ?', timestamp).destroy_all
Not quite sure what broke on your end, but his works for me in my console using a basic Rails model.

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

Inject route from gem to rails 3 routes.rb using Railties (devise issue)

I would like to automatically inject a route from my gem to the host app using a railtie. So far I have something like this:
module Fabes
class FabesRailtie < ::Rails::Railtie
ActionController::Base.send :include, Fabes::Helper
ActionController::Base.helper Fabes::Helper
initializer 'fabes.routes', after: :after_initialize do |app|
app.routes.draw do
match '/fabes' => Fabes::Admin, as: :fabes_admin
end
end
end
end
This is working (is getting called from the host app) but when I try to access the /fabes route or just list the routes, it is failing with a devise error:
fuzzyalej#fuzzyalej:~/code/fabes-rails-example (master *)$ rake routes --trace
** Invoke routes (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
undefined method `failure_app=' for nil:NilClass
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise.rb:406:in `configure_warden!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.1.2/lib/devise/rails/routes.rb:20:in `finalize_with_devise!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/actionpack-3.2.6/lib/action_dispatch/routing/route_set.rb:261:in `draw'
/Users/fuzzyalej/code/fabes/lib/fabes/railtie.rb:7:in `block in <class:FabesRailtie>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `instance_exec'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:30:in `run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/initializable.rb:54:in `run_initializers'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:136:in `initialize!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/railtie/configurable.rb:30:in `method_missing'
/Users/fuzzyalej/code/fabes-rails-example/config/environment.rb:5:in `<top (required)>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `block in require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:in `require'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:103:in `require_environment!'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/railties-3.2.6/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/bin/rake:23:in `load'
/Users/fuzzyalej/.rbenv/versions/1.9.3-p194/bin/rake:23:in `<main>'
Tasks: TOP => routes => environment
I don't know if I can inject a route directly like this or instead I would have to use a generator..
Any thoughts on the issue?
Defining your routes in your gem's route.rb file and then mounting the engine is the way to go in this case.
The "official guide":
http://edgeguides.rubyonrails.org/engines.html
And of course, there's a RailsCast episode covering what you likely need:
http://railscasts.com/episodes/277-mountable-engines
Hope this helps.

Rails: Custom Rake Task error => rake aborted! missing :controller

(RoR with Rails 3.1, gem rake 0.9.2.2)
I'm trying to run the most basic custom rake task as you can see here:
task :update_me => :environment do
Product.all.each do |product|
puts product.link
end
end
I keep getting the error below. The task will run if I just print out hello world and take out the ":environment" part. My rake task seems to be having trouble with the ":environment" part of this, but I need this to access my models.
rake aborted!
missing :controller
Tasks: TOP => update_me => environment
(See full trace by running task with --trace)
trace:
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:179:in `default_controller_and_action'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:76:in `normalize_options!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:59:in `initialize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `new'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1302:in `add_route'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1282:in `decomposed_match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `block in match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:1268:in `match'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:505:in `map_method'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/mapper.rb:467:in `get'
/home/ubuntu/code/preevio/config/routes.rb:35:in `block in <top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:282:in `eval_block'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/actionpack-3.2.3/lib/action_dispatch/routing/route_set.rb:260:in `draw'
/home/ubuntu/code/preevio/config/routes.rb:1:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `block in load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:40:in `load_paths'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:16:in `reload!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:26:in `block in updater'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `call'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/file_update_checker.rb:78:in `execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:27:in `updater'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/ubuntu/code/preevio/config/environment.rb:5:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application.rb:103:in `require_environment!'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/railties-3.2.3/lib/rails/application.rb:292:in `block (2 levels) in initialize_tasks'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `call'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:205:in `block in execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:200:in `execute'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:158:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:176:in `block in invoke_prerequisites'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:174:in `invoke_prerequisites'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:157:in `block in invoke_with_call_chain'
/home/ubuntu/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:151:in `invoke_with_call_chain'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/task.rb:144:in `invoke'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:116:in `invoke_task'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block (2 levels) in top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `each'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:94:in `block in top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:88:in `top_level'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:66:in `block in run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/gems/rake-0.9.2.2/bin/rake:33:in `<top (required)>'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/bin/rake:19:in `load'
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290#rails31/bin/rake:19:in `<main>'
The backtrace seems to indicate an error in the routes file, which is loaded when you require the environment.
In these cases, running rake routes will bring further information on the problem.