I am trying to display user's email in the view with User.find(#id).email,but it gives me an error couldn't find user without id,but i am sure the #id carries id 3,because <%=#id%> displays 3.Another thing If i hard code the id as User.find(3).email it displays the email succesfully.The problem occurs only when i put #id variable as a parameter in the find method,what is going on here?Thank you in advance.
View/profile.html.erb
<% #books.each do |book|%>
<%=book.user_id %> =>displays 3
<%= User.find(book.user_id).email %> =>cant find the id
<%=User.find(3).email%> =>works fine
Error
Couldn't find User without an ID
activerecord (3.1.0.rc8) lib/active_record/relation/finder_methods.rb:302:in `find_with_ids'
activerecord (3.1.0.rc8) lib/active_record/relation/finder_methods.rb:107:in `find'
activerecord (3.1.0.rc8) lib/active_record/base.rb:441:in `find'
app/views/deal/show.html.erb:83:in `block (2 levels) in _app_views_deal_show_html_erb__772775201_99014040'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
app/views/deal/show.html.erb:80:in `block in _app_views_deal_show_html_erb__772775201_99014040'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
app/views/deal/show.html.erb:13:in `_app_views_deal_show_html_erb__772775201_99014040'
actionpack (3.1.0.rc8) lib/action_view/template.rb:144:in `block in render'
activesupport (3.1.0.rc8) lib/active_support/notifications.rb:55:in `instrument'
actionpack (3.1.0.rc8) lib/action_view/template.rb:142:in `render'
actionpack (3.1.0.rc8) lib/action_view/renderer/template_renderer.rb:40:in `block (2levels) in render_template'n/finder_methods.rb:302:in `find_with_ids'
activerecord (3.1.0.rc8) lib/active_record/relation/finder_methods.rb:107:in `find'
activerecord (3.1.0.rc8) lib/active_record/base.rb:441:in `find'
app/views/deal/show.html.erb:83:in `block (2 levels) in _app_views_deal_show_html_erb__772775201_99014040'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
activerecord (3.1.0.rc8) lib/active_record/relation.rb:15:in `each'
app/views/deal/show.html.erb:80:in `block in _.........................
Ensure that #id is an integer. If it is, I don't see why it wouldn't work. I just tried the exact same thing in my own application and it worked fine.
To ensure that #id is an integer and not a string, try this:
<%= User.find(#id.to_i).email %>
If that does not work, please copy/paste your exact error back here so we can look further into the problem.
Related
since yesterday, my production app starts to raise ActiveRecord::ImmutableRelation in some queries of my entire application!
I can't imagine how to gives an exact context of every error since this error occurs on random places of my application! I can't simulate this errors calling the same block of code in Rails Console, only in the controllers in production environment.
We don't change any query, I become to think this can be a bug or some change in the database configuration(?).
Did someone already get this errors? Any idea what I can search for?
Backtrace (of one error):
ActiveRecord::ImmutableRelation: ActiveRecord::ImmutableRelation
from active_record/relation/query_methods.rb:923:in `assert_mutability!'
from active_record/relation/query_methods.rb:915:in `set_value'
from active_record/relation/query_methods.rb:74:in `references_values='
from active_record/relation/query_methods.rb:176:in `references!'
from active_record/relation/merger.rb:76:in `block in merge'
from active_record/relation/merger.rb:66:in `each'
from active_record/relation/merger.rb:66:in `merge'
from active_record/relation/spawn_methods.rb:45:in `merge!'
from octopus/relation_proxy.rb:49:in `public_send'
from octopus/relation_proxy.rb:49:in `block in method_missing'
from octopus/proxy.rb:86:in `block (2 levels) in run_queries_on_shard'
from octopus/proxy.rb:345:in `using_shard'
from octopus/proxy.rb:85:in `block in run_queries_on_shard'
from octopus/proxy.rb:329:in `keeping_connection_proxy'
from octopus/proxy.rb:84:in `run_queries_on_shard'
from octopus/shard_tracking.rb:31:in `run_on_shard'
from octopus/relation_proxy.rb:45:in `method_missing'
from active_record/associations/association.rb:79:in `scope'
from active_record/associations/collection_association.rb:288:in `scope'
from active_record/associations/collection_proxy.rb:960:in `scope'
from active_record/associations/collection_proxy.rb:1130:in `order'
from octopus/relation_proxy.rb:49:in `public_send'
from octopus/relation_proxy.rb:49:in `block in method_missing'
from octopus/proxy.rb:86:in `block (2 levels) in run_queries_on_shard'
from octopus/proxy.rb:345:in `using_shard'
from octopus/proxy.rb:85:in `block in run_queries_on_shard'
from octopus/proxy.rb:329:in `keeping_connection_proxy'
from octopus/proxy.rb:84:in `run_queries_on_shard'
from octopus/shard_tracking.rb:31:in `run_on_shard'
from octopus/relation_proxy.rb:45:in `method_missing'
from app/controllers/v2/app/details_controller.rb:9:in `show'
from action_controller/metal/basic_implicit_render.rb:6:in `send_action'
from abstract_controller/base.rb:194:in `process_action'
from scout_apm/instruments/action_controller_rails_3_rails4.rb:72:in `process_action'
from action_controller/metal/rendering.rb:30:in `process_action'
from abstract_controller/callbacks.rb:42:in `block in process_action'
from active_support/callbacks.rb:109:in `block in run_callbacks'
from raven/integrations/rails/controller_transaction.rb:7:in `block in included'
from active_support/callbacks.rb:118:in `instance_exec'
from active_support/callbacks.rb:118:in `block in run_callbacks'
from active_support/callbacks.rb:136:in `run_callbacks'
from abstract_controller/callbacks.rb:41:in `process_action'
from action_controller/metal/rescue.rb:22:in `process_action'
from action_controller/metal/instrumentation.rb:34:in `block in process_action'
from active_support/notifications.rb:168:in `block in instrument'
from active_support/notifications/instrumenter.rb:23:in `instrument'
from active_support/notifications.rb:168:in `instrument'
from action_controller/metal/instrumentation.rb:32:in `process_action'
from action_controller/metal/params_wrapper.rb:256:in `process_action'
from active_record/railties/controller_runtime.rb:24:in `process_action'
from scout_apm/instruments/action_controller_rails_3_rails4.rb:94:in `process_action'
from abstract_controller/base.rb:134:in `process'
from action_controller/metal.rb:191:in `dispatch'
from action_controller/metal.rb:252:in `dispatch'
from action_dispatch/routing/route_set.rb:52:in `dispatch'
from action_dispatch/routing/route_set.rb:34:in `serve'
from action_dispatch/journey/router.rb:52:in `block in serve'
from action_dispatch/journey/router.rb:35:in `each'
from action_dispatch/journey/router.rb:35:in `serve'
from action_dispatch/routing/route_set.rb:840:in `call'
from scout_apm/instruments/rails_router.rb:29:in `call_with_scout_instruments'
from rails_api_utils/middleware/context_collect.rb:18:in `call'
from rails_api_utils/middleware/localization.rb:29:in `block (2 levels) in call'
from active_support/core_ext/time/zones.rb:66:in `use_zone'
from rails_api_utils/middleware/localization.rb:39:in `in_timezone'
from rails_api_utils/middleware/localization.rb:28:in `block in call'
from i18n.rb:297:in `with_locale'
from rails_api_utils/middleware/localization.rb:43:in `with_locale'
from rails_api_utils/middleware/localization.rb:27:in `call'
from rack/request_id.rb:30:in `block in call'
from request_id.rb:60:in `with'
from rack/request_id.rb:29:in `call'
from scout_apm/middleware.rb:17:in `call'
from request_store/middleware.rb:9:in `call'
from rack/etag.rb:25:in `call'
from rack/conditional_get.rb:25:in `call'
from rack/head.rb:12:in `call'
from action_dispatch/middleware/callbacks.rb:28:in `block in call'
from active_support/callbacks.rb:98:in `run_callbacks'
from action_dispatch/middleware/callbacks.rb:26:in `call'
from enterprise/trace_id/middlewares/rack_middleware.rb:21:in `block in call'
from enterprise/trace_id/tracer/tracer.rb:13:in `block in trace'
from <internal:prelude>:137:in `__enable'
from <internal:prelude>:137:in `enable'
from enterprise/trace_id/tracer/tracer.rb:13:in `trace'
from enterprise/trace_id/middlewares/rack_middleware.rb:21:in `call'
from action_dispatch/middleware/debug_exceptions.rb:61:in `call'
from action_dispatch/middleware/show_exceptions.rb:33:in `call'
from rails/rack/logger.rb:38:in `call_app'
from rails/rack/logger.rb:26:in `block in call'
from active_support/tagged_logging.rb:71:in `block in tagged'
from active_support/tagged_logging.rb:28:in `tagged'
from active_support/tagged_logging.rb:71:in `tagged'
from rails/rack/logger.rb:26:in `call'
from action_dispatch/middleware/remote_ip.rb:81:in `call'
from request_store/middleware.rb:9:in `call'
from action_dispatch/middleware/request_id.rb:27:in `call'
from rack/runtime.rb:22:in `call'
from active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
from action_dispatch/middleware/executor.rb:14:in `call'
from rack/sendfile.rb:111:in `call'
from raven/integrations/rack.rb:51:in `call'
from scout_apm/instruments/middleware_summary.rb:58:in `call'
from rails/engine.rb:524:in `call'
from puma/configuration.rb:225:in `call'
from puma/server.rb:658:in `handle_request'
from puma/server.rb:472:in `process_client'
from puma/server.rb:332:in `block in run'
from puma/thread_pool.rb:133:in `block in spawn_thread'
Details controller code (I've omitted some enterprises model names):
# frozen_string_literal: true
class DetailsController < V2::ApplicationController
def show
model = Model.find(params[:pricing_id])
details = model.details.order(:position)
details.each { |detail| detail.model = model }
Detail.cascade_formula_arguments(details, params)
details = details.select(&:available?)
render json: details, each_serializer: ::V2::DetailSerializer
end
end
Unless you wish to modify the data I would suggest mapping this to an array of hashes... but not sure what Detail.cascade_formula_arguments(details, params) is doing so this is a guess.
I would try to convert the data to hash instead of active record object unless you really are trying to modify them so something like this:
details.each { |detail| detail.model = model }
details = details.map(&:as_json)
Updated
Based on comments by #engineersmnky, and my own thought that this line of code is likely where your problem is, can you just remove this line of code? What is its purpose? See if you can remove it.
# try to remove this from your code
details.each { |detail| detail.model = model }
I have a custom rake task and I am using a mailer with this task. I have an agent table with all of an agent's info. I also have an agent_card table that houses all of their license data. The agent_card table also has an agent_id column to identify which card goes with which agent. When trying to run the rake task and send out the mailer, I keep getting "ActionView::Template::Error: undefined method `name' for nil:NilClass." I can't figure out how to get the name, email, and phone through the agent_card table. I have included all the code below. Please and thank you!
Error:
rake aborted!
ActionView::Template::Error: undefined method `name' for nil:NilClass
/Users/michaelwiesenhart/Code/app/views/license_expire_mailer/license_expi re_mgr.html.erb:7:in `_app_views_license_expire_mailer_license_expire_mgr_html_erb___944550213720770297_70323524541360'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:145:in `block in render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:166:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:333:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/template.rb:143:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:54:in `block (2 levels) in render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/abstract_renderer.rb:39:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:53:in `block in render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:61:in `render_with_layout'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:52:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/template_renderer.rb:14:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:46:in `render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/renderer/renderer.rb:27:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:100:in `_render_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:83:in `render_to_body'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/rendering.rb:25:in `render'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:904:in `block in collect_responses'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:918:in `each_template'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:900:in `collect_responses'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:829:in `mail'
/Users/michaelwiesenhart/Code/app/mailers/license_expire_mailer.rb:14:in `license_expire_mgr'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:198:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/callbacks.rb:81:in `run_callbacks'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionpack-4.2.6/lib/abstract_controller/base.rb:137:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionview-4.2.6/lib/action_view/rendering.rb:30:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:596:in `block in process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `block in instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activesupport-4.2.6/lib/active_support/notifications.rb:164:in `instrument'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:593:in `process'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/base.rb:584:in `initialize'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `new'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:25:in `__getobj__'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:34:in `message'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/actionmailer-4.2.6/lib/action_mailer/message_delivery.rb:85:in `deliver_now'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:17:in `block (3 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:15:in `block (2 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#/bin/ruby_executable_hooks:15:in `eval'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#/bin/ruby_executable_hooks:15:in `<main>'
Agent Model:
has_one :agent_card
AgentCard Model:
belongs_to :agent
license_expire_mgr.html.erb
Hiya, <br><br>
The agent listed below has a license that will expire one week from today. Please make sure they renew before it expires!<br><br>
<strong>Name:</strong> <%= #agent.name %><br>
<strong>Phone:</strong> <%= #agent.phone %><br>
<strong>Email:</strong> <%= #agent.email %><br><br>
license_expire_mailer.rb
class LicenseExpireMailer < ActionMailer::Base
default from: "Mike <help#mike.com>"
def license_expire_mgr(agent_card, agent)
#agent_cards = agent_card
#agent = agent
mail to: "mike#mike.com", subject: "Agent License Expiring"
end
end
#agent is not being passed through to the mailer or the value of it is being evaluated as nil.
The problem is not with your rake task or your mailer, figure out why the param is nil and that will solve your problem.
I figured it out. I was trying to use agent_card and didn't need it. Once I removed it, it works just fine!
i'm having troubles with Devise Gem, i'm using the default recoverable methods, the links is being sent. The reset values (reset_password_sent_at) is saved in the database, but when i have to write down the new password and update it, gives this error
NoMethodError (undefined method `to_datetime' for nil:NilClass):
activesupport (4.0.2) lib/active_support/core_ext/date_time/calculations.rb:161:in `<=>'
activesupport (4.0.2) lib/active_support/core_ext/time/calculations.rb:286:in `compare_with_coercion'
activesupport (4.0.2) lib/active_support/time_with_zone.rb:214:in `<=>'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `=='
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `!='
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:97:in `_field_changed?'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:66:in `write_attribute'
activerecord (4.0.2) lib/active_record/attribute_methods/time_zone_conversion.rb:39:in `reset_password_sent_at='
devise (3.5.6) lib/devise/models/recoverable.rb:94:in `clear_reset_password_token'
devise (3.5.6) lib/devise/models/recoverable.rb:32:in `block (2 levels) in <module:Recoverable>'
activesupport (4.0.2) lib/active_support/callbacks.rb:377:in `_run__1626105923374900797__update__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.2) lib/active_record/callbacks.rb:310:in `update_record'
activerecord (4.0.2) lib/active_record/timestamp.rb:70:in `update_record'
activerecord (4.0.2) lib/active_record/persistence.rb:477:in `create_or_update'
activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `block in create_or_update'
activesupport (4.0.2) lib/active_support/callbacks.rb:393:in `_run__1626105923374900797__save__callbacks'
activesupport (4.0.2) lib/active_support/callbacks.rb:80:in `run_callbacks'
activerecord (4.0.2) lib/active_record/callbacks.rb:302:in `create_or_update'
activerecord (4.0.2) lib/active_record/persistence.rb:106:in `save'
activerecord (4.0.2) lib/active_record/validations.rb:51:in `save'
activerecord (4.0.2) lib/active_record/attribute_methods/dirty.rb:32:in `save'
activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block (2 levels) in save'
activerecord (4.0.2) lib/active_record/transactions.rb:326:in `block in with_transaction_returning_status'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `block in transaction'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:210:in `within_new_transaction'
activerecord (4.0.2) lib/active_record/connection_adapters/abstract/database_statements.rb:202:in `transaction'
activerecord (4.0.2) lib/active_record/transactions.rb:209:in `transaction'
activerecord (4.0.2) lib/active_record/transactions.rb:323:in `with_transaction_returning_status'
activerecord (4.0.2) lib/active_record/transactions.rb:270:in `block in save'
activerecord (4.0.2) lib/active_record/transactions.rb:281:in `rollback_active_record_state!'
activerecord (4.0.2) lib/active_record/transactions.rb:269:in `save'
devise (3.5.6) lib/devise/models/recoverable.rb:48:in `reset_password'
devise (3.5.6) lib/devise/models/recoverable.rb:141:in `reset_password_by_token'
devise (3.5.6) app/controllers/devise/passwords_controller.rb:32:in `update'
debugging this its seems to be a problem with the reset_password_sent_at being nil when the password is reset (lib/devise/models/recoverable.rb:94:inclear_reset_password_token)
I've try to change my local time to the UTC stored but the problem isn't that. Any suggestion?
My solution for this was to upgrade my rails from 4.0.2 to 4.2.7. When i run the bundle install and update the gemfile dependencies now is working.
Upgrading devise from (3.5.6) to (4.2.0)
I have composite_primary_keys gem install and used with Rails 4.2.0.rc2, and I keep getting a
undefined method `ensure_initialized' for #<ActiveRecord::AttributeSet:0x007fcb319ed988>
error from this line:
Array(self.class.primary_key).each {|key| #attributes.ensure_initialized(key)}
Stack:
/Users/mmahalwy/.rvm/gems/ruby-2.1.2/bundler/gems/composite_primary_keys-0a8061943732/lib/composite_primary_keys/core.rb:6:in `block in init_internals'
/Users/mmahalwy/.rvm/gems/ruby-2.1.2/bundler/gems/composite_primary_keys-0a8061943732/lib/composite_primary_keys/core.rb:6:in `each'
/Users/mmahalwy/.rvm/gems/ruby-2.1.2/bundler/gems/composite_primary_keys-0a8061943732/lib/composite_primary_keys/core.rb:6:in `init_internals'
activerecord (4.2.0.rc2) lib/active_record/core.rb:274:in `initialize'
activerecord (4.2.0.rc2) lib/active_record/inheritance.rb:61:in `new'
activerecord (4.2.0.rc2) lib/active_record/inheritance.rb:61:in `new'
delayed_job (4.0.2) lib/delayed/backend/base.rb:29:in `enqueue'
activejob (4.2.0.rc2) lib/active_job/queue_adapters/delayed_job_adapter.rb:18:in `enqueue'
activejob (4.2.0.rc2) lib/active_job/enqueuing.rb:71:in `block in enqueue'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:117:in `call'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:190:in `block in simple'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:338:in `call'
activesupport (4.2.0.rc2) lib/active_support/callbacks.rb:338:in `block (2 levels) in simple'
activejob (4.2.0.rc2) lib/active_job/logging.rb:14:in `call'
This is caused by a bug in the version you are using for the gem. update the gem:
bundle update composite_primary_keys
and try again.
There are a lot of rake tests failing in a ruby on rails project [1], all with same error (can't convert nil into String), and I don't have any idea why is this happening neither how I should debug it.
For example, this is the first tracebak of rake test (I have attached full rake test traceback at the end of the message [2]).
Error:
test_update(Admin::BazarDistrictsControllerTest):
TypeError: can't convert nil into String
/usr/lib/ruby/1.9.1/psych.rb:154:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'
/usr/lib/ruby/1.9.1/psych.rb:125:in `parse'
/usr/lib/ruby/1.9.1/psych.rb:112:in `load'
/srv/www/gamersmafia/current/app/models/users_skill.rb:178:in `role_data_yaml'
/srv/www/gamersmafia/current/app/models/alert.rb:200:in `block in update_pending_alerts'
/srv/www/gamersmafia/current/app/models/alert.rb:198:in `each'
/srv/www/gamersmafia/current/app/models/alert.rb:198:in `update_pending_alerts'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/performable_method.rb:26:in `perform'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:95:in `block in invoke_job'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in `call'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:60:in `block in initialize'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in `call'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:65:in `execute'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/lifecycle.rb:38:in `run_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:92:in `invoke_job'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:37:in `block in enqueue'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:36:in `tap'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/backend/base.rb:36:in `enqueue'
/usr/lib/ruby/gems/1.9.1/gems/delayed_job-3.0.5/lib/delayed/message_sending.rb:13:in `method_missing'
/srv/www/gamersmafia/current/app/models/alert.rb:182:in `block in update_pending_alerts'
/srv/www/gamersmafia/current/app/models/alert.rb:180:in `each'
/srv/www/gamersmafia/current/app/models/alert.rb:180:in `update_pending_alerts'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:460:in `_run__1673722312823048322__save__808729243992924512__callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/callbacks.rb:264:in `create_or_update'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/persistence.rb:84:in `save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/validations.rb:50:in `save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/attribute_methods/dirty.rb:22:in `save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:259:in `block (2 levels) in save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:313:in `block in with_transaction_returning_status'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in `transaction'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:208:in `transaction'
/usr/lib/ruby/gems/1.9.1/gems/deadlock_retry-1.2.0/lib/deadlock_retry.rb:31:in `transaction_with_deadlock_handling'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:311:in `with_transaction_returning_status'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:259:in `block in save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:270:in `rollback_active_record_state!'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/transactions.rb:258:in `save'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/persistence.rb:45:in `create'
/srv/www/gamersmafia/current/app/models/bazar_district.rb:158:in `update_single_person_staff'
/srv/www/gamersmafia/current/app/models/bazar_district.rb:83:in `update_don'
/srv/www/gamersmafia/current/app/controllers/admin/bazar_districts_controller.rb:43:in `update'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:167:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/rendering.rb:10:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:503:in `block in _run__1141341086633682237__process_action__2809844012775858444__callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:215:in `block in _conditional_callback_around_5310'
/srv/www/gamersmafia/current/app/controllers/application_controller.rb:233:in `block (2 levels) in gm_process'
/srv/www/gamersmafia/current/app/controllers/application_controller.rb:232:in `catch'
/srv/www/gamersmafia/current/app/controllers/application_controller.rb:232:in `block in gm_process'
/usr/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/srv/www/gamersmafia/current/app/controllers/application_controller.rb:231:in `gm_process'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:214:in `_conditional_callback_around_5310'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:469:in `_run__1141341086633682237__process_action__2809844012775858444__callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:405:in `__run_callback'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/callbacks.rb:81:in `run_callbacks'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/callbacks.rb:17:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/rescue.rb:29:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `block in instrument'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support/notifications.rb:123:in `instrument'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/activerecord-3.2.12/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/base.rb:121:in `process'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/rendering.rb:45:in `process'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/metal/testing.rb:17:in `process_with_new_base_test'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:473:in `process'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:49:in `process'
/usr/lib/ruby/gems/1.9.1/gems/actionpack-3.2.12/lib/action_controller/test_case.rb:395:in `post'
/srv/www/gamersmafia/current/test/functional/admin/bazar_districts_controller_test.rb:42:in `block in <class:BazarDistrictsControllerTest>'
And I have more than 200 test with errors of a total of 1448 tests.
The question is, from where must I start to debug it? Why I'm getting same error in +90% of tests?
[1] https://github.com/gamersmafia/gamersmafia
[2] https://dl.dropbox.com/u/42306424/salida_rake.txt
In case of debugging. I reccomend to use gem 'pry-rails'.
Just bundle this gem and add 'binding.pry' to failing test. It will open console with all variables from your test, so you can manually check it. I hope it helps you to find out what's wrong.
It's might be one of the problems of Cucumber version.
You can fix this by upgrading cucumber-rails to a recent version. Just edit your Gemfile to show this:
gem 'cucumber-rails', '>= 1.1.1' or newer version
its solved my error when i got the same.
In your case, its pointed delayed_job gem
If you are using bundler try prefixing the script or rake task with "bundle exec" e.g.
bundle exec script/delayed_job -n 2 start
and Try!!!!