2014-10-17 56 views
0

我們複製/粘貼Devise註冊控制器及其一些方法來調整事物。正常。爲什麼不會在我的數據庫中設計更新屬性?

update方法是這樣的:

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 protected]", 
     "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 

他們訪問 - 和所有其他PARAMS得到更新就好了。只有這兩個沒有被觸及。

爲什麼

+0

你有什麼在模型中驗證可能會阻止更新? – mmichael 2014-10-17 18:42:45

回答

0

原來,根本不是設計。

別人在這個可愛的小TID位選中了:

# 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. 

...

相關問題