ruby on rails - How can the value get updated in update_attribute -
i have test, needs set database-state:
before site.first.update_attribute(:primary_domain, @params[:order][:primary_domain]) end
but, reason, modifies @params:
before @params[:order][:primary_domain].must_equal "example.com" site.first.update_attribute(:primary_domain, @params[:order][:primary_domain]) @params[:order][:primary_domain].must_equal "example.com" end
this fails, second @params[:order][:primary_domain].must_equal "example.com"
fails, updates @params[:order][:primary_domain]
there. weird, have expected update_attribute(name, value)
not touch value
, somehow, does.
it can circumvented .dup
. interested cause this. maybe scope issue? fact normalising site.primary_domain
on save
, maybe?
# override primary_domain setter. # allows normalise domain def primary_domain=(primary_domain) return primary_domain unless primary_domain.is_a?(string) write_attribute(:primary_domain, site.parse_uri(primary_domain.dup).host) end
Comments
Post a Comment