ruby on rails - Strange update issue -
i have piece of code updates person information.
module people class update attr_reader :person_id, :params def call person_id, params @person_id = person_id @params = params update_person end def update_person @person = person.find(person_id) @person.update(params) @person end end end
params equals
{"first_name"=>"blue", "last_name"=>"panther", "email"=>"bluepanther9@gs.co.za"}
person_id has value , exists in database. pretty simple , straight forward.
the weird thing error when executes through application, works fine when through rspec or console manually. see error below.
activemodel::forbiddenattributeserror /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activemodel-4.2.0.beta4/lib/active_model/forbidden_attributes_protection.rb:21:in `sanitize_for_mass_assignment' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:33:in `assign_attributes' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:249:in `block in update' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:248:in `update' /storage/www/testing.phoenix.site.co.za/app/services/people/update.rb:14:in `update_person' /storage/www/testing.phoenix.site.co.za/app/services/people/update.rb:9:in `call' /storage/www/testing.phoenix.site.co.za/app/services/people/create_or_update_person.rb:24:in `create_or_update_person' /storage/www/testing.phoenix.site.co.za/app/services/people/create_or_update_person.rb:15:in `call' /storage/www/testing.phoenix.site.co.za/app/services/events/incoming/identify.rb:19:in `create_or_update_person' /storage/www/testing.phoenix.site.co.za/app/services/events/incoming/identify.rb:13:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/performable_method.rb:30:in `perform' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:94:in `block in invoke_job' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:91:in `invoke_job' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:199:in `block (2 levels) in run' /home/getsmart/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:91:in `block in timeout' /home/getsmart/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `call' /home/getsmart/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/timeout.rb:101:in `timeout' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:199:in `block in run' /home/getsmart/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:198:in `run' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:in `block in reserve_and_run_one_job' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:in `reserve_and_run_one_job' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:182:in `block in work_off' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:in `times' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:in `work_off' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:146:in `block (4 levels) in start' /home/getsmart/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/benchmark.rb:294:in `realtime' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:145:in `block (3 levels) in start' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:144:in `block (2 levels) in start' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:in `loop' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:in `block in start' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:clearlocks>' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `block in add' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:142:in `start' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:124:in `run' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:112:in `block in run_process' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `block in start_proc' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call_as_daemon' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application.rb:259:in `start_proc' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application.rb:296:in `start' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application_group.rb:159:in `block (2 levels) in start_all' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `fork' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `block in start_all' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `each' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `start_all' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/controller.rb:80:in `run' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons.rb:197:in `block in run_proc' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/daemons-1.1.9/lib/daemons.rb:196:in `run_proc' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:110:in `run_process' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:91:in `block in daemonize' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:89:in `times' /home/getsmart/.rvm/gems/ruby-2.1.2@phoenix/gems/delayed_job-4.0.4/lib/delayed/command.rb:89:in `daemonize' bin/delayed_job:5:in `<main>'
note code being executed delayed job. not sure if make difference.
you should replace with
@person.update(params.permit(:first_name, :last_name, :email))
you should not use permit!
blindly, point ensure people can change allow.
Comments
Post a Comment