Displaying 20 results from an estimated 20000 matches similar to: "update_attribute works, update_attributes doesn''t, why?"
2006 Jun 26
0
Update_attributes working, or not? I can''t tell.
I have a basic login system implemented. I''ve recently added a
timestamp field "last_activity_time". During the login process, if I
successfully get back a user object, I do this:
user.update_attribute(:last_activity_time, Time.now())
It appears to be successful given the breadcrumbs I''ve strewn around it,
but nothing gets written out to my table. In
2006 Jan 17
2
update_attribute and validations
Just in case it saves someone else the several hours of insanity I just
went through, update_attributes will not save unless the model
validations are satisfied, but update_attribute (the singular form)
will save the attribute to the database even if the model validations
would fail!
This appears to be a feature, not a bug
(http://api.rubyonrails.com/classes/ActiveRecord/Base.html) although
2006 Jan 15
0
update_attributes not working
I dont know if its me or the dodgy win-32 intall of ruby/mysql, but I
can''t seem to get update_attributes to work.
In my user controller, I have:
def update
@user = User.find(@params[''user'']["id"])
if @user.update_attributes(@params["user"])
flash["success"] = "Updated Successfully"
redirect_to :action =>
2007 Nov 21
3
update_attribute weirdness in edge
If I am changing a boolean value, no matter what approach I take, I
get the same results:
lets say table "users" has an "enabled" field that is boolean:
user = User.find(1)
user.enabled.toggle
NoMethodError: undefined method `toggle'' for false:FalseClass
user = User.find(1)
toggle(user.enabled)
NoMethodError: undefined method `toggle'' for
2006 Feb 27
4
update_attribute with Validation?
Does anyone know of a way to update individual attributes with
validation? update_attribute disables the validation checks in the
record model, so I''m wondering if there''s a workaround for this.
In my application, I want to allow the user to update some or all the
attributes without having to enter :password and :password_confirmation,
both of which are subject to
2008 Apr 19
1
update and update_attribute woes
i can not get update to work via controller/server.
it works via console ???
this is what i get when i run it
Club Load (0.005893) SELECT * FROM clubs WHERE (clubs."id" = 3)
SQL (0.000570) BEGIN
SQL (0.000454) COMMIT
club.update_attributes(:state => "CA")
or
Club.update(3, :state => "CA")
what am i overlooking?
2006 Jun 27
1
user.save now workie, but user.update_attributes does
In my User model, I had this:
def update_last_login_time
self.last_login = Time.now
self.save
end
But last_login was not being set.
When I changed it to this it worked:
self.update_attribute( :last_login, Time.now )
Any ideas why?
~S
2011 May 21
1
Consequences of overriding update_attribute to force validation?
I know the debate of whether this should validate has been rehashed
many times. My question is, what are the consequences of overriding
this method to force validation? Will this break fundamental things?
Will it break plugins? Is there a reason not to have a strict
validation option?
In my code I will never use this as I consider it a terribly broken
method, but some gems use it and in one case
2008 Jan 21
1
specin'' update_attributes! + Hash
Hi,
I am facing a problem while trying to test a method that updates an
attribute. The attribute format should be converted to YAML format
before storing in the table which is excatly what is going on. But when
testing it using expectations in rspec it returns an error.
*** below is the error message :
Spec::Mocks::MockExpectationError in ''InteractController (submit) -
saving a form to
2009 Feb 03
1
update_attributes! does not update nested model
Hi!
I have updated my app to rails 2.3. I have form that has few nested
models and I am happy that I can just write
accepts_nested_attributes_for :tasks, :allow_destroy => true, but
update_attributes! does not update my nested model. I have tried
update_attributes, and it works. Any ideas?
Few lines from log:
update_attributes:
SQL (0.1ms) BEGIN
Education Update (0.3ms) UPDATE
2006 Jan 03
5
update command not updating DB
I really need your help guys... I spent 6 hours on this simple update
command today that should work. It works fine in my other controller,
but doesn''t work in this one for some reason.
Here is my controller code for the list view, and then the update
command:
======
def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if
2008 Aug 26
1
transaction not working with update_attributes!
I am trying to wrap the updating of two models in a transaction and
when the transaction fails it is not rolling back.
My method is :
def update_attributes(user,params)
@user = user
@company = user.company
begin
User.transaction do
@user.update_attributes!(params[:user])
@company.update_attributes!(params[:company])
end
true
rescue
false
2008 Aug 25
2
to catch exception from update_attribute
Hi
begin
ActiveRecord::Base.transaction do
pb_status_history = ProblemStatusHistory.new
pb_status_history.problem_id = @problem.id
pb_status_history.problem_status_id =
@problem.problem_status_id
pb_status_history.save!
ret_val=@problem.update_attribute("problem_status_id",''ab'')
if ret_val==false
2006 Jul 11
3
update_attributes and save!
I notice that ActiveRecord::Base.update_attributes() calls save().
What if I want to get an exception if the save fails? Is there a way to
get the update_attributes() function plus the save! function?
Thanks,
Wes
--
Posted via http://www.ruby-forum.com/.
2010 Sep 01
0
Error on update_attributes with HABTM relationship
Hope someone can tell me what''s up, because this has me baffled.
I have an Image model, and a Provider model. Both are defined as
"has_and_belongs_to_many" relating to each other. In my image form
partial, I have a bit of AJAX generating the provider_ids array
dynamically from a provider AJAX search on the same page.
So for example, each time I click on a provider name that
2006 Apr 28
1
@model.update_attributes(params[:model]) without saving?
Is it possible to update the parameters from a form without saving?
@model.update_attributes(params[:model]) will save the model after
updating its attributes. I''d just like the attributes updating without
a save.
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2008 Feb 08
2
update_Attributes stale Object error
Hi,
IN one of my unit tests I get an ActiveRecord::StaleObjectError:
Attempted to update a stale object
object.save!
in object I have apart from other stuff an after_save method, which
calls
object.assosication.update_attributes(...)
If I remove that line from my code my tests succeeds.
Unfortunetly, I do not understand why an update_attributes call can
generate an StaleObjectError.
Maybe
2006 Sep 04
3
Having trouble with update_attributes() after member access
I''m having problems in a controller i am writing. i get this exception:
wrong number of arguments (1 for 0)
## this does not work:
@voicemail_user = VoicemailUser.find(session[:asterisk][:user_id])
if (@voicemail_user.password == params[:pwd][:current])
@voicemail_user.update_attributes({"password" =>
params[:pwd][:newpwd2]})
end
## but this works:
2008 Apr 28
1
update_attribute overwrites existing attributes with NULL.
Hmm.
When using update_attribute from within a worker method, it seems that
Backgroundrb inserts null values into all attributes that are not
explicitly set. Is this possible/true?
2007 Mar 25
1
Optimistic locking and update_attributes: not working?
Hi all,
I''ve searched the forumns, but I can''t seem to find an answer to this
one. I''m having trouble getting optimistic locking (OL) to work in my
app, even though all of the pieces are there:
* table has lock_version column, with default of 0 (zero)
* lock_version column is being incremented by the first update (but the
second doesn''t catch it)
*