我正在覆盖设计用户的注册控制器以检查用户是否更改了城市,如果是,则在会话中再次加载 Geokit 对象。
session[:geo_location] = User.geocode(resource.city) if resource.city_changed?
问题是没有这样做。下面的代码没有返回任何内容。如果我删除if resource.city_changed?
它,它适用于所有情况,无论资源是否已更改。
User::RegistrationsController < Devise::RegistrationsController
def update
self.resource = resource_class.to_adapter.get!(send(:"current_# {resource_name}").to_key)
if resource.update_with_password(params[resource_name])
session[:geo_location] = User.geocode(resource.city) if resource.city_changed?
set_flash_message :notice, :updated if is_navigational_format?
sign_in resource_name, resource, :bypass => true
respond_with resource, :location => after_update_path_for(resource)
else
clean_up_passwords(resource)
respond_with_navigational(resource){ render_with_scope :edit }
end
end
end