undefined method `first' on update in rails - ruby-on-rails

I import a csv file into my DB and i have a error when I update it.
My error :
undefined method `first' for nil:NilClass
on line "if agent.update(line)"
My model :
def self.import_agent(file)
fallback = {:counter => 0}
CSV.foreach(file.path, :col_sep => "\t", :headers => true, :quote_char => "\x00", :encoding => 'windows-1251:utf-8') do |row|
line = Hash.new
row.to_hash.each_pair do |k,v|
row ={k.downcase.gsub("agent_", "") => v}
line = line.deep_merge(row)
end
agent = Agent.find_or_initialize_by(code:line["code"])
if agent.update(line)
fallback[:counter] += 1
end
end
return fallback
end
My Controller :
def import_agent
#file = params[:file]
fallback = Import.import_agent(#file)
redirect_to root_path, notice: 'File successfully uploaded, '+fallback[:counter].to_s+' line are added/updated !'
end
Error Log :
Started POST "/import_agent" for 127.0.0.1 at 2015-03-30 11:06:18 +0200
Processing by ImportsController#import_agent as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"pF1GsZ+Z+9tHmiw6k47Y7T7Sjn1ka1bHZqMqwWbBO2QIHBIz2VX9F7kPGP0CyYT6xu3nJnANJdGjDCtE0eISjw==", "file"=>#<ActionDispatch::Http::UploadedFile:0x007ff3d9fccba8 #tempfile=#<Tempfile:/var/folders/xw/pqcy6hjd59x29wf0wqcbhp1h0000gn/T/RackMultipart20150330-7818-f99zac.csv>, #original_filename="EXPORT_AGENT.csv", #content_type="text/csv", #headers="Content-Disposition: form-data; name=\"file\"; filename=\"EXPORT_AGENT.csv\"\r\nContent-Type: text/csv\r\n">, "commit"=>"Import Agent CSV"}
Agent Load (0.3ms) SELECT "agents".* FROM "agents" WHERE "agents"."code" = ? LIMIT 1 [["code", "AG001"]]
(0.1ms) begin transaction
(0.1ms) rollback transaction
Completed 500 Internal Server Error in 62ms
NoMethodError - undefined method `first' for nil:NilClass:
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:114:in `find_parameter_position'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:103:in `block in extract_callstack_for_multiparameter_attributes'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:98:in `extract_callstack_for_multiparameter_attributes'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:76:in `assign_multiparameter_attributes'
activerecord (4.2.0) lib/active_record/attribute_assignment.rb:46:in `assign_attributes'
activerecord (4.2.0) lib/active_record/persistence.rb:249:in `block in update'
activerecord (4.2.0) lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/persistence.rb:248:in `update'
app/models/import.rb:67:in `block in import_agent'
/Users/gregoryfrerot/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/csv.rb:1739:in `each'
/Users/gregoryfrerot/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/csv.rb:1122:in `block in foreach'
/Users/gregoryfrerot/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/csv.rb:1273:in `open'
/Users/gregoryfrerot/.rvm/rubies/ruby-2.2.0/lib/ruby/2.2.0/csv.rb:1121:in `foreach'
app/models/import.rb:60:in `import_agent'
app/controllers/imports_controller.rb:16:in `import_agent'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
bullet (4.14.4) lib/bullet/rack.rb:12:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.0) lib/rack/etag.rb:24:in `call'
rack (1.6.0) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.0) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.0) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.0) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.0) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.0) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.0) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.0) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.0) lib/rack/content_length.rb:15:in `call'
thin (1.6.3) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.3) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.3) lib/thin/connection.rb:53:in `process'
thin (1.6.3) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.0.5) lib/eventmachine.rb:187:in `run'
thin (1.6.3) lib/thin/backends/base.rb:73:in `start'
thin (1.6.3) lib/thin/server.rb:162:in `start'
rack (1.6.0) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.0) lib/rack/server.rb:286:in `start'
railties (4.2.0) lib/rails/commands/server.rb:80:in `start'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.0) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:4:in `<main>'
Thanks for your help and sorry for my english.

Use find_or_create_by instead of find_or_initialize_by, since the latter does not insert new record into database.

Related

why Rails call a method does't exist in current version(4.2.0)?

I works on a Rails project, using Rails 4.2.0, gemfile:
gem 'rails', '4.2.0'
# other gems.........
we have these two models:
class shop < ActiveRecord::Base
has_many :shop_categories
end
class ShopCategory < ActiveRecord::Base
# has a column named "shop_id"
belongs_to :shop
def self.some_max(shop)
# line number: 33
where(shop: shop).maximum(:some_value)
end
end
and we have a generator, which will call the "some_max" method on ShopCategory:
# simplified, but just like this
shop = Shop.first
# lib/generators/shop/build/build_generator.rb:36
ShopCategory.some_max shop
and the generator is invoked by code inside our Rails application:
# app/services/shop_service.rb:8
Rails::Generators.invoke 'shop:build', [..params..]
and we get this error:
NoMethodError (undefined method `convert_value_to_association_ids' for ActiveRecord::PredicateBuilder:Class):
composite_primary_keys (8.1.3) lib/composite_primary_keys/relation/predicate_builder.rb:24:in `expand'
activerecord (4.2.0) lib/active_record/relation/predicate_builder.rb:43:in `block in build_from_hash'
activerecord (4.2.0) lib/active_record/relation/predicate_builder.rb:21:in `each'
activerecord (4.2.0) lib/active_record/relation/predicate_builder.rb:21:in `build_from_hash'
activerecord (4.2.0) lib/active_record/relation/query_methods.rb:958:in `build_where'
activerecord (4.2.0) lib/active_record/relation/query_methods.rb:584:in `where!'
activerecord (4.2.0) lib/active_record/relation/query_methods.rb:574:in `where'
activerecord (4.2.0) lib/active_record/querying.rb:10:in `where'
app/models/shop_category.rb:33:in `block in <class:ShopCategory>'
activerecord (4.2.0) lib/active_record/scoping/named.rb:155:in `call'
activerecord (4.2.0) lib/active_record/scoping/named.rb:155:in `block (2 levels) in scope'
activerecord (4.2.0) lib/active_record/relation.rb:302:in `scoping'
activerecord (4.2.0) lib/active_record/scoping/named.rb:155:in `block in scope'
app/models/shop_category.rb:28:in `block in <class:ShopCategory>'
activesupport (4.2.0) lib/active_support/callbacks.rb:443:in `instance_exec'
activesupport (4.2.0) lib/active_support/callbacks.rb:443:in `block in make_lambda'
activesupport (4.2.0) lib/active_support/callbacks.rb:163:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:163:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_create_callbacks'
activerecord (4.2.0) lib/active_record/callbacks.rb:306:in `_create_record'
activerecord (4.2.0) lib/active_record/timestamp.rb:57:in `_create_record'
activerecord (4.2.0) lib/active_record/persistence.rb:501:in `create_or_update'
activerecord (4.2.0) lib/active_record/callbacks.rb:302:in `block in create_or_update'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:219:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_save_callbacks'
activerecord (4.2.0) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.2.0) lib/active_record/persistence.rb:120:in `save'
activerecord (4.2.0) lib/active_record/validations.rb:37:in `save'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
activerecord (4.2.0) lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block in save'
activerecord (4.2.0) lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
activerecord (4.2.0) lib/active_record/transactions.rb:285:in `save'
activerecord (4.2.0) lib/active_record/associations/singular_association.rb:79:in `_create_record'
activerecord (4.2.0) lib/active_record/associations/singular_association.rb:21:in `create'
activerecord (4.2.0) lib/active_record/associations/builder/singular_association.rb:22:in `create_shop_category'
lib/generators/shop/build/build_generator.rb:36:in `create_shop_category'
lib/generators/shop/build/build_generator.rb:30:in `copy_shop_files'
thor (0.19.1) lib/thor/command.rb:27:in `run'
thor (0.19.1) lib/thor/invocation.rb:126:in `invoke_command'
thor (0.19.1) lib/thor/invocation.rb:133:in `block in invoke_all'
thor (0.19.1) lib/thor/invocation.rb:133:in `each'
thor (0.19.1) lib/thor/invocation.rb:133:in `map'
thor (0.19.1) lib/thor/invocation.rb:133:in `invoke_all'
thor (0.19.1) lib/thor/group.rb:232:in `dispatch'
thor (0.19.1) lib/thor/base.rb:440:in `start'
railties (4.2.0) lib/rails/generators.rb:157:in `invoke'
app/services/shop_service.rb:8:in `build'
app/controllers/after_registers_controller.rb:180:in `go_shop_step'
app/controllers/after_registers_controller.rb:107:in `go_retail_steps'
app/controllers/after_registers_controller.rb:46:in `update'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
rack-raw-upload (1.1.1) lib/rack/raw_upload.rb:18:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `catch'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
remotipart (1.2.1) lib/remotipart/middleware.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:20:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `catch'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack-cors (0.4.0) lib/rack/cors.rb:80:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
thin (1.6.4) lib/thin/connection.rb:86:in `block in pre_process'
thin (1.6.4) lib/thin/connection.rb:84:in `catch'
thin (1.6.4) lib/thin/connection.rb:84:in `pre_process'
thin (1.6.4) lib/thin/connection.rb:53:in `process'
thin (1.6.4) lib/thin/connection.rb:39:in `receive_data'
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run_machine'
eventmachine (1.2.0.1) lib/eventmachine.rb:194:in `run'
thin (1.6.4) lib/thin/backends/base.rb:73:in `start'
thin (1.6.4) lib/thin/server.rb:162:in `start'
rack (1.6.4) lib/rack/handler/thin.rb:19:in `run'
rack (1.6.4) lib/rack/server.rb:286:in `start'
railties (4.2.0) lib/rails/commands/server.rb:80:in `start'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:80:in `block in server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `tap'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:75:in `server'
railties (4.2.0) lib/rails/commands/commands_tasks.rb:39:in `run_command!'
railties (4.2.0) lib/rails/commands.rb:17:in `<top (required)>'
bin/rails:8:in `require'
bin/rails:8:in `<top (required)>'
spring (1.7.1) lib/spring/client/rails.rb:28:in `load'
spring (1.7.1) lib/spring/client/rails.rb:28:in `call'
spring (1.7.1) lib/spring/client/command.rb:7:in `call'
spring (1.7.1) lib/spring/client.rb:30:in `run'
spring (1.7.1) bin/spring:49:in `<top (required)>'
spring (1.7.1) lib/spring/binstub.rb:11:in `load'
spring (1.7.1) lib/spring/binstub.rb:11:in `<top (required)>'
/home/robin/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/home/robin/.rvm/rubies/ruby-2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
bin/spring:13:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Rendered /home/robin/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_source.erb (12.4ms)
Rendered /home/robin/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.1ms)
Rendered /home/robin/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.3ms)
Rendered /home/robin/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (32.8ms)
I understood this errore happened when Rails try convert this line:
where(shop: shop).maximum(:some_value)
to something like that:
# when I change the line above to this, the error disappeared
where(shop_id: shop.id).maximum(:some_value)
also, I checked the Rails document, and found that ActiveRecord::PredicateBuilder has a class method called "convert_value_to_association_ids" in Rails version 4.2.1, but not in 4.2.0. So why Rails call a method does't exist in current version(4.2.0)? Does this have something to do with the environment of the generator invoking? Thanks in advance.
===========================================
Update:
In my rails project, i run "bundle show activerecord", it give me a path to my activerecord gem, and follow this path, I open the file in "lib/active_record/relation/predicate_builder.rb", and I can't find the class method "convert_value_to_association_ids" in this file.
The error is actually coming from composite_primary_keys, v8.1.3, not rails/activerecord:
value = convert_value_to_association_ids(value, primary_key)
It uses this method, even though it depends on activerecord 4.2.0, in which the method does not yet exist. It's a bug in that version of the composite_primary_keys gem.

Rails 4. Devise gem. Argument out of range

I can't find a solution. I would like to create new User in my web application (with Devise). Please, read the notes below:
My current OS: Ubuntu 15
Previous OS: Linux Mint
(On Mac OS X it works correctly)
Terminal log:
Started POST "/users" for 127.0.0.1 at 2016-03-04 00:40:32 +0300
Processing by Users::RegistrationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"OmTevxMT8IYxO8fcWHJU75gsLhVlj6/dLctvU2PhIWnlsEZ2B0p0iCQClVmPbRKBBauBKfjwv1hRnP8kTC0sxg==", "user"=>{"name"=>"test", "surname"=>"test", "email"=>"test#test.ru", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Зарегистрироваться"}
(0.3ms) BEGIN
User Exists (0.7ms) SELECT 1 AS one FROM `users` WHERE `users`.`email` = BINARY 'test#test.ru' LIMIT 1
SQL (0.6ms) INSERT INTO `users` (`email`, `encrypted_password`, `name`, `surname`, `created_at`, `updated_at`) VALUES ('test#test.ru', '$2a$10$sY490xgy8sHCFJxfY2B80OSFV7s.p0qg8R03ZPLGjzGYqou8Lz6xC', 'test', 'test', '2016-03-03 21:40:32.488474', '2016-03-03 21:40:32.488474')
(44.3ms) COMMIT
Completed 500 Internal Server Error in 201ms
ArgumentError - argument out of range:
activesupport (4.2.0) lib/active_support/values/time_zone.rb:350:in `parse'
activesupport (4.2.0) lib/active_support/core_ext/string/zones.rb:9:in `in_time_zone'
activerecord (4.2.0) lib/active_record/attribute_methods/time_zone_conversion.rb:15:in `type_cast_from_user'
activerecord (4.2.0) lib/active_record/attribute.rb:100:in `type_cast'
activerecord (4.2.0) lib/active_record/attribute.rb:42:in `original_value'
activerecord (4.2.0) lib/active_record/attribute.rb:37:in `value'
activerecord (4.2.0) lib/active_record/attribute.rb:46:in `value_for_database'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:164:in `store_original_raw_attribute'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:93:in `write_attribute'
activerecord (4.2.0) lib/active_record/attribute_methods.rb:50:in `__temp__c6163747f5379676e6f596e6f59607'
devise (3.5.5) lib/devise/models/trackable.rb:24:in `update_tracked_fields'
devise (3.5.5) lib/devise/models/trackable.rb:32:in `update_tracked_fields!'
devise (3.5.5) lib/devise/hooks/trackable.rb:7:in `block in '
warden (1.2.6) lib/warden/hooks.rb:14:in `block in _run_callbacks'
warden (1.2.6) lib/warden/hooks.rb:9:in `_run_callbacks'
warden (1.2.6) lib/warden/manager.rb:51:in `_run_callbacks'
warden (1.2.6) lib/warden/proxy.rb:179:in `set_user'
devise (3.5.5) lib/devise/controllers/sign_in_out.rb:43:in `sign_in'
devise (3.5.5) app/controllers/devise/registrations_controller.rb:106:in `sign_up'
devise (3.5.5) app/controllers/devise/registrations_controller.rb:22:in `create'
app/controllers/users/registrations_controller.rb:12:in `create'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/mapper.rb:49:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
warden (1.2.6) lib/warden/manager.rb:34:in `call'
rack (1.6.4) lib/rack/etag.rb:24:in `call'
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.4) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
web-console (2.3.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (2.3.0) lib/web_console/middleware.rb:18:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
puma (2.16.0) lib/puma/server.rb:557:in `handle_request'
puma (2.16.0) lib/puma/server.rb:404:in `process_client'
puma (2.16.0) lib/puma/server.rb:270:in `block in run'
puma (2.16.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
I have added changes to my model, but my error is the same:
class Something < ActiveRecord::Base
validate :important_date_is_valid_datetime, on: :create
validates :important_date, presence: true
private
def important_date_is_valid_datetime
if (DateTime.parse(important_date.to_s()) rescue ArgumentError) == ArgumentError then
errors.add(:important_date, 'must be a valid datetime')
end
end
end
Also, I have added the next code in my form:
class Something < ActiveRecord::Base
validate :important_date_is_valid_datetime, on: :create
validates :important_date, presence: true
private
def important_date_is_valid_datetime
if (DateTime.parse(important_date.to_s()) rescue ArgumentError) == ArgumentError then
errors.add(:important_date, 'must be a valid datetime')
end
end
end

"Ruby on Rails Tutorial" by Michael Hartl Ch 10. undefined method `rest_digest=' for #<User:0x007f3c04f08e20>

I need some help. The problem is when I try submitting an email to reset a password, I get the following error.
Application trace gives the following
app/models/user.rb:57:in `create_reset_digest'
app/controllers/password_resets_controller.rb:8:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"/jhl+HQLT42IZLH2ashW6y2fpSiUY+htnOSq4oQPeUTrkHDbaj2IvLYEmt5209E7BJV07nJK/1PH+lE1CkUgUw==",
"password_reset"=>"[FILTERED]",
"commit"=>"Submit"}
Framework trace:
activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing'
activerecord (4.2.0) lib/active_record/persistence.rb:238:in `update_attribute'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
rack (1.6.1) lib/rack/handler/webrick.rb:89:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Full Trace
app/models/user.rb:57:in `create_reset_digest'
app/controllers/password_resets_controller.rb:8:in `create'
activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing'
activerecord (4.2.0) lib/active_record/persistence.rb:238:in `update_attribute'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:38:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
rack (1.6.1) lib/rack/handler/webrick.rb:89:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
I think you wrote "rest_digest", should be "reset_digest"
May be you wanted to assign a value to the reset_digest attribute and not rest_digest (note the typo).

Rails not finding record by ID, even though it exists

I have a rails app that displays the games in an NFL week. So, if the user navigates to: url.com/week/1/ it will display all of the games.
The format is: /week/:id
The controller looks like this:
def show
#week = Week.find(params[:id])
#user = User.first #place holder until current_user is implemented
#games = #week.games
end
When I go to check the page I get:
ActiveRecord::RecordNotFound in WeekController#show
Couldn't find Week with 'id'=
Extracted source (around line #154):
152
153
154
155
156
157
record = s.execute([id], self, connection).first
unless record
raise RecordNotFound, "Couldn't find #{name} with '# {primary_key}'=#{id}"
end
record
rescue RangeError
The id is blank, though I don't understand why, because it's in the parameters:
Request
Parameters:
{"id"=>"4"}
I can verify using the rails console that this record/week should exist, but rails can't find it for some reason... this was working fine and all of a sudden stopped working when I added some validations to another model, but I don't see how they can be related. This is a really simple query.
Any thoughts?
edit: Trace included below:
app/models/pick.rb:31:in `pick_within_range'
app/controllers/week_controller.rb:16:in `block in show'
app/controllers/week_controller.rb:11:in `show'
activerecord (4.2.0) lib/active_record/core.rb:154:in `find'
activesupport (4.2.0) lib/active_support/callbacks.rb:427:in `block in make_lambda'
activesupport (4.2.0) lib/active_support/callbacks.rb:189:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:189:in `block in simple'
activesupport (4.2.0) lib/active_support/callbacks.rb:190:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:190:in `block in simple'
activesupport (4.2.0) lib/active_support/callbacks.rb:190:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:190:in `block in simple'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_validate_callbacks'
activemodel (4.2.0) lib/active_model/validations.rb:395:in `run_validations!'
activemodel (4.2.0) lib/active_model/validations/callbacks.rb:113:in `block in run_validations!'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_validation_callbacks'
activemodel (4.2.0) lib/active_model/validations/callbacks.rb:113:in `run_validations!'
activemodel (4.2.0) lib/active_model/validations.rb:334:in `valid?'
activerecord (4.2.0) lib/active_record/validations.rb:58:in `valid?'
activerecord (4.2.0) lib/active_record/validations.rb:83:in `perform_validations'
activerecord (4.2.0) lib/active_record/validations.rb:37:in `save'
activerecord (4.2.0) lib/active_record/attribute_methods/dirty.rb:21:in `save'
activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block (2 levels) in save'
activerecord (4.2.0) lib/active_record/transactions.rb:347:in `block in with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:220:in `transaction'
activerecord (4.2.0) lib/active_record/transactions.rb:344:in `with_transaction_returning_status'
activerecord (4.2.0) lib/active_record/transactions.rb:286:in `block in save'
activerecord (4.2.0) lib/active_record/transactions.rb:301:in `rollback_active_record_state!'
activerecord (4.2.0) lib/active_record/transactions.rb:285:in `save'
activerecord (4.2.0) lib/active_record/relation/delegation.rb:46:in `each'
activerecord (4.2.0) lib/active_record/relation/delegation.rb:46:in `each'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call'
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
rack (1.6.1) lib/rack/content_length.rb:15:in `call'
rack (1.6.1) lib/rack/handler/webrick.rb:89:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'

Unable to get serializer to serialize has_many association

So I am using the latest active_model_serializer and I am trying to use them to send an array on Medium.
I use this to make a query for the Medium: Medium.includes([{comments: :user}, :user]).where(user_id: user_ids)
So the Medium belong to a user, medium has many comments and every comment has a user (owner).
Now here are the corresponding serializers:
Medium:
class MediumSerializer < ActiveModel::Serializer
attributes :id,
:text,
:image_video_file_name,
:image_video_croppable_url,
:image_video_thumb_url,
:image_video_big_url
belongs_to :user
has_many :comments
end
Comment:
class CommentSerializer < ActiveModel::Serializer
attributes :id,
:text,
:user_id,
:medium_id
belongs_to :user
end
User:
class UserSerializer < ActiveModel::Serializer
include Avatar
attributes :id,
:name,
:email,
:role,
:avatar
def avatar
Medium.find(self.current_avatar)[0]
end
#has_one :avatar, serializer: AvatarSerializer
has_many :media, :comments
end
And also I have these functions in my Medium:
def image_video_croppable_url
image_video.url(:croppable)
end
def image_video_thumb_url
image_video.url(:thumb)
end
def image_video_big_url
image_video.url(:big)
end
I use Paperclip gem and I needed these functions to get access to sizes of different medium images. Maybe there is a better way for it also.
So now when I do the query, I use this line to pass the info to browser and let the serializer make it JSON nicely:
respond_with media, each_serializer: MediumSerializer
But it gives me this error:
NoMethodError - undefined method `image_video_file_name' for #<Comment:0x007f5a082a4310>:
activemodel (4.2.0) lib/active_model/attribute_methods.rb:433:in `method_missing'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:37:in `block (2 levels) in attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:200:in `block in attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `each_with_object'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:198:in `attributes'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:22:in `block (3 levels) in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter.rb:53:in `cache_check'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:21:in `block (2 levels) in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:20:in `map'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:20:in `block in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:224:in `call'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:224:in `block in each_association'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:208:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer.rb:208:in `each_association'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:17:in `serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `block in serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/array_serializer.rb:5:in `each'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `map'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter/json.rb:9:in `serializable_hash'
active_model_serializers (0.10.0.rc1) lib/active_model/serializer/adapter.rb:23:in `as_json'
activesupport (4.2.0) lib/active_support/json/encoding.rb:34:in `encode'
activesupport (4.2.0) lib/active_support/json/encoding.rb:21:in `encode'
activesupport (4.2.0) lib/active_support/core_ext/object/json.rb:37:in `to_json_with_active_support_encoder'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:116:in `block in <module:Renderers>'
active_model_serializers (0.10.0.rc1) lib/action_controller/serialization.rb:49:in `block (2 levels) in <module:Serialization>'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:45:in `block in _render_to_body_with_renderer'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/set.rb:283:in `each_key'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/set.rb:283:in `each'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:41:in `_render_to_body_with_renderer'
actionpack (4.2.0) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
actionpack (4.2.0) lib/abstract_controller/rendering.rb:25:in `render'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:16:in `render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block (2 levels) in render'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/home/kaspar/.rbenv/versions/2.2.0/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
activesupport (4.2.0) lib/active_support/core_ext/benchmark.rb:12:in `ms'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:41:in `block in render'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:84:in `cleanup_view_runtime'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:40:in `render'
responders (2.1.0) lib/action_controller/responder.rb:258:in `display'
responders (2.1.0) lib/action_controller/responder.rb:212:in `api_behavior'
responders (2.1.0) lib/action_controller/responder.rb:191:in `rescue in to_format'
responders (2.1.0) lib/action_controller/responder.rb:185:in `to_format'
responders (2.1.0) lib/action_controller/responder.rb:163:in `respond'
responders (2.1.0) lib/action_controller/responder.rb:156:in `call'
responders (2.1.0) lib/action_controller/respond_with.rb:203:in `respond_with'
app/controllers/users_controller.rb:73:in `feed'
actionpack (4.2.0) lib/action_controller/metal/implicit_render.rb:4:in `send_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:198:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rendering.rb:10:in `process_action'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:151:in `block in halting_and_conditional'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:234:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:169:in `block in halting'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:92:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_process_action_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.0) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.0) lib/active_support/notifications.rb:164:in `instrument'
actionpack (4.2.0) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.2.0) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
activerecord (4.2.0) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
actionpack (4.2.0) lib/abstract_controller/base.rb:137:in `process'
actionview (4.2.0) lib/action_view/rendering.rb:30:in `process'
actionpack (4.2.0) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.2.0) lib/action_controller/metal.rb:236:in `block in action'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:42:in `serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `each'
actionpack (4.2.0) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.0) lib/action_dispatch/routing/route_set.rb:802:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.6.1) lib/rack/etag.rb:24:in `call'
rack (1.6.1) lib/rack/conditionalget.rb:25:in `call'
rack (1.6.1) lib/rack/head.rb:13:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/flash.rb:260:in `call'
rack (1.6.1) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.6.1) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/cookies.rb:560:in `call'
activerecord (4.2.0) lib/active_record/query_cache.rb:36:in `call'
activerecord (4.2.0) lib/active_record/connection_adapters/abstract/connection_pool.rb:647:in `call'
activerecord (4.2.0) lib/active_record/migration.rb:378:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `call'
activesupport (4.2.0) lib/active_support/callbacks.rb:88:in `_run_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:734:in `_run_call_callbacks'
activesupport (4.2.0) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (4.2.0) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/reloader.rb:73:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.0) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `block in tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:26:in `tagged'
activesupport (4.2.0) lib/active_support/tagged_logging.rb:68:in `tagged'
railties (4.2.0) lib/rails/rack/logger.rb:20:in `call'
quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
actionpack (4.2.0) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.1) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.1) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.0) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.1) lib/rack/lock.rb:17:in `call'
actionpack (4.2.0) lib/action_dispatch/middleware/static.rb:113:in `call'
rack (1.6.1) lib/rack/sendfile.rb:113:in `call'
railties (4.2.0) lib/rails/engine.rb:518:in `call'
railties (4.2.0) lib/rails/application.rb:164:in `call'
passenger (5.0.7) lib/phusion_passenger/rack/thread_handler_extension.rb:89:in `process_request'
passenger (5.0.7) lib/phusion_passenger/request_handler/thread_handler.rb:149:in `accept_and_process_next_request'
passenger (5.0.7) lib/phusion_passenger/request_handler/thread_handler.rb:110:in `main_loop'
passenger (5.0.7) lib/phusion_passenger/request_handler.rb:414:in `block (3 levels) in start_threads'
passenger (5.0.7) lib/phusion_passenger/utils.rb:111:in `block in create_thread_and_abort_on_exception'
This error only occurs when I attempt to throw an array of Medium to the Serializer. With only one Medium I get no errors and the result is this:
As you can see it has all the attributes I wanted it to have in the serializer and it managed to fetch the info into all the attributes with no problems.
Why does this problem occur only when I do the same thing with an array or same objects?

Resources