我得到SyntaxError - syntax error, unexpected '=', expecting keyword_end
當我使用send
方法來將字符串轉換爲我的Rails應用程序中的對象。什麼奇怪的是,這是當我使用它的值進行比較的東西,像這樣的工作發現:SyntaxError - 語法錯誤,意外的'=',期望使用send方法時的keyword_end Rails
if @whiteboard.contract.send(user_ast_contract_accept) == true
....
end
但是,當我用它來更新的價值,我得到的錯誤。下面是完整的錯誤:
SyntaxError - syntax error, unexpected '=', expecting keyword_end
user.send(user_credit_check) = "Submitted"
^:
app/controllers/whiteboards_controller.rb:355:in `'
activesupport (4.2.3) lib/active_support/dependencies.rb:457:in `block in load_file'
activesupport (4.2.3) lib/active_support/dependencies.rb:647:in `new_constants_in'
activesupport (4.2.3) lib/active_support/dependencies.rb:456:in `load_file'
activesupport (4.2.3) lib/active_support/dependencies.rb:354:in `require_or_load'
activesupport (4.2.3) lib/active_support/dependencies.rb:494:in `load_missing_constant'
activesupport (4.2.3) lib/active_support/dependencies.rb:184:in `const_missing'
activesupport (4.2.3) lib/active_support/inflector/methods.rb:261:in `block in constantize'
activesupport (4.2.3) lib/active_support/inflector/methods.rb:259:in `constantize'
activesupport (4.2.3) lib/active_support/dependencies.rb:566:in `get'
activesupport (4.2.3) lib/active_support/dependencies.rb:597:in `constantize'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:72:in `controller_reference'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:62:in `controller'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:41:in `serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:43:in `block in serve'
actionpack (4.2.3) lib/action_dispatch/journey/router.rb:30:in `serve'
actionpack (4.2.3) lib/action_dispatch/routing/route_set.rb:821:in `call'
下面是我的代碼,包括我提出的功能:
def get_member_position(user, contract)
if user.id == contract.tenant1.to_i
return "tenant1"
elsif user.id == contract.tenant2.to_i
return "tenant2"
elsif user.id == contract.tenant3.to_i
return "tenant3"
elsif user.id == contract.tenant4.to_i
return "tenant4"
elsif user.id == contract.landlord.to_i
return "landlord"
elsif user.id == contract.guarantor1.to_i
return "guarantor1"
elsif user.id == contract.guarantor2.to_i
return "guarantor2"
elsif user.id == contract.guarantor3.to_i
return "guarantor3"
elsif user.id == contract.guarantor4.to_i
return "guarantor4"
else
end
end
def get_user_credit_check(user, contract)
member_position = get_member_position(user, contract)
user_credit_check = member_position + "_credit_check"
return user_credit_check
end
contract = Contract.find(params[:contract_id])
user_credit_check = get_user_credit_check(current_user, contract)
contract.send(user_credit_check) = "Submitted"
contract.save
啊謝謝...錯誤現在對我有意義,這解決了我的問題! –