How do I catch and return a warning when the edited values are not the same causing rails to not开发者_运维百科 perform an UPDATE?
You could handle it in your controller. In a basic update definition :
def update
if birth_date_changed? && @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
redirect_to post_url(@post)
else
flash[:warning] = 'Birth date did not changed' unless birth_date_changed?
render :action => "edit"
end
end
private
def birth_date_changed?
@user.birth_date != params[:user][:birth_date]
end
精彩评论