Checking if an attribute changed after commit in Rails -


i know using dirty or changed? useful in before_commit situation or before model saved. after model saved, previous_changes gives changes. great. but,

how can check if specific attribute changed in controller if looks like

def update  @item = item.find(params[:id]) if @item.update_attributes(item_params)  # horray  # check if :name changed, if else  # d'oh end end 

is there better way doing !@item.previous_changes[:name].nil?

i not know if there better way, do:

if @item.previous_changes.has_key?('name')   # name has been changed. end 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -