1
我有一段代碼更新人員信息。奇怪的更新問題
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等於
{"first_name"=>"Blue", "last_name"=>"Panther", "email"=>"[email protected]"}
爲person_id具有的價值和存在於數據庫中。非常簡單直接。
奇怪的是,當所有事情都通過應用程序執行時,我得到一個錯誤,但是當我通過rspec或控制檯手動執行時,它會正常工作。看到下面的錯誤。
ActiveModel::ForbiddenAttributesError
/home/getsmart/.rvm/gems/[email protected]/gems/activemodel-4.2.0.beta4/lib/active_model/forbidden_attributes_protection.rb:21:in `sanitize_for_mass_assignment'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/attribute_assignment.rb:33:in `assign_attributes'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/persistence.rb:249:in `block in update'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:345:in `block in with_transaction_returning_status'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/transaction.rb:188:in `within_new_transaction'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:218:in `transaction'
/home/getsmart/.rvm/gems/[email protected]/gems/activerecord-4.2.0.beta4/lib/active_record/transactions.rb:342:in `with_transaction_returning_status'
/home/getsmart/.rvm/gems/[email protected]/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/[email protected]/gems/delayed_job-4.0.4/lib/delayed/performable_method.rb:30:in `perform'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:94:in `block in invoke_job'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/backend/base.rb:91:in `invoke_job'
/home/getsmart/.rvm/gems/[email protected]/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/[email protected]/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/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:198:in `run'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:in `block in reserve_and_run_one_job'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:275:in `reserve_and_run_one_job'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:182:in `block in work_off'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:in `times'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:181:in `work_off'
/home/getsmart/.rvm/gems/[email protected]/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/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:145:in `block (3 levels) in start'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:144:in `block (2 levels) in start'
/home/getsmart/.rvm/gems/[email protected]phoenix/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:in `loop'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:143:in `block in start'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:61:in `block in initialize'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:79:in `block in add'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:66:in `execute'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/worker.rb:142:in `start'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:124:in `run'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:112:in `block in run_process'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application.rb:255:in `block in start_proc'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/daemonize.rb:82:in `call_as_daemon'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application.rb:259:in `start_proc'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application.rb:296:in `start'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application_group.rb:159:in `block (2 levels) in start_all'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `fork'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application_group.rb:158:in `block in start_all'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `each'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/application_group.rb:157:in `start_all'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/controller.rb:80:in `run'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons.rb:197:in `block in run_proc'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `call'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons/cmdline.rb:109:in `catch_exceptions'
/home/getsmart/.rvm/gems/[email protected]/gems/daemons-1.1.9/lib/daemons.rb:196:in `run_proc'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:110:in `run_process'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:91:in `block in daemonize'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:89:in `times'
/home/getsmart/.rvm/gems/[email protected]/gems/delayed_job-4.0.4/lib/delayed/command.rb:89:in `daemonize' bin/delayed_job:5:in `<main>'
請注意,代碼正在從延遲作業執行。不知道這是否會有所作爲。
會update_attributes不跳過驗證? –
@ Ryan-NealMes不,它不是 – usmanali
@ Ryan-NealMes根本沒有,'update'和'update_attributes'都是別名btw – apneadiving