我们已经复制/粘贴了Devise注册控制器及其中一些调整方法。正常。
更新方法如下所示:
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
ap account_update_params
resource_updated = resource.update_attributes(account_update_params)
yield resource if block_given?
if resource_updated
if is_flashing_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
else
clean_up_passwords resource
respond_with resource
end
end
我将ap account_update_params放在那里以确保我在更新前获得所有正确的内容:
{
"email" => "email@address.com",
"first_name" => "Foo",
"last_name" => "Bar",
"user_type" => "1",
"company" => "Company",
"phone" => "555-555-5555",
"temp_units" => "c",
"volume_measure" => "0",
"address_1" => "1234 Anywhere Ln",
"address_2" => "",
"city" => "Somewhere",
"province" => "CA",
"postal" => "90210",
"country_id" => "201"
}
是的,他们都在那里。
问题在于:temp_units和volume_measure永远不会更新。
型号:
attr_accessible :email,
:password,
:password_confirmation,
:remember_me,
:temp_units,
:first_name,
:last_name,
:company,
:address_1,
:address_2,
:city,
:province,
:postal,
:phone,
:country_id,
:volume_measure,
:user_type
他们可以访问 - 所有其他参数都可以更新。只有这两个人没有被触及。
为什么
答案 0 :(得分:0)
事实证明它根本没有设计。
其他人已经检查了这个漂亮的小小点:
# This is used after user creation.
# If the user is from USA it will set the user's
# default locale to inferior measurement units.
def set_locale
if [201, 200].include?(self.country_id)
self.temp_units = "f"
self.volume_measure = User::VOLUME_MEASURE_GALLONS
else
self.temp_units = "c"
self.volume_measure = User::VOLUME_MEASURE_LITERS
end
end
并嵌套在模型顶部附近:
before_save :set_locale # Changed from after_save.
...