【发布时间】:2014-12-23 16:44:11
【问题描述】:
我的问题是关于连接到 Close.io API 并专门更新与潜在客户关联的自定义字段 - http://developer.close.io/#Leads
它在您的文档中声明...
custom:更新单个自定义字段而不删除其他字段, 使用 custom.field_name: updated_value 而不是 custom: { all: '字段',列出:'这里'}。您还可以通过以下方式取消设置单个字段 使用 custom.field_name: null。
但这在我们的项目中引起了一些怪癖。对单个字段的每次更新都会继续删除其他字段。
这是我们的代码 -
# We're using the close.io gem ( a ruby wrapper ) - https://github.com/taylorbrooks/closeio
# First we get the signed in user's email address
# and query closeio to pull the appropriate lead associated with it
closeio_lead_id = (Closeio::Lead.where query: "email:['#{current_user.email}']")[0]['id']
#Next we're attempting to update the lead custom field of "kk_referral" with a float
(Closeio::Lead.update closeio_lead_id,
custom: { kk_referral: Referral.where( :user_id => current_user.id).count.to_f }
)
# And it works! Yay But then we run the next line to update another custom field...
# the last action is erased. what the hell?
(Closeio::Lead.update closeio_lead_id,
custom.kk_blog_posts_submitted: Comment.where( :user_id => current_user.id).count.to_f
)
# So we attempted to store the in a variable so we can replicate some of the direction provided in the documentation.
closeio_comment = Comment.where( :user_id => current_user.id).count.to_f
(Closeio::Lead.update closeio_lead_id,
custom.kk_blog_posts_submitted: closeio_comment
)
# And nothing is coming through. AHhhh. Only the original syntax works.
尝试使用文档中提供的语法时......
custom.field_name: some_variable_storing_a_float
我收到与 field_name 后面的冒号有关的语法错误。
当尝试使用更友好的 Ruby 语法时......
custom.field_name => some_variable_storing_a_float
我在使用自定义局部变量时出错。 (准确的读作“NameError: undefined local variable or method `custom' for main:Object)
有什么建议吗?谢谢!
【问题讨论】:
标签: ruby ruby-on-rails-4 ruby-2.0