2

Deviseユーザーの登録コントローラーを上書きして、ユーザーが都市を変更したかどうかを確認し、変更した場合は、セッションで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
4

1 に答える 1

4

update_with_password電話しますsaveか?その場合、モデルとそのすべての属性の「ダーティ」状態をクリアします。属性を設定したresource.city_changed? 後、を呼び出す前に呼び出す必要がありますsave

于 2012-04-25T00:40:15.143 に答える