similar to: quick question: are errors best checked on controllers by stubbing save/update_attributes?

Displaying 20 results from an estimated 40000 matches similar to: "quick question: are errors best checked on controllers by stubbing save/update_attributes?"

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 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
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/.
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
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
2010 May 16
0
update_attributes for nested form
I have two models. model A has_many :b def before_validation_on_create ......... end model B belongs_to :a In b''s controller and ''update'' action, I have a.update_attributes(params[ :a ]) So when I was trying to create a new ''b'', before_validation_on_create is being called twice. Pleas let me know if you guys have any suggestions. Thanks in
2007 May 17
2
Stubbing authentication across multiple controllers
Hi, I''m new to RSpec, so I''m not too sure of the best practises in stubbing. I was thinking along the lines of including a helper method that would stub out a users id and posts to sessions/create. It works fine when speccing SessionsController, but of course it fails when it is included into other controllers specs, because of the post. I''ve tried posting to an
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 =>
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 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
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) *
2007 Mar 28
1
attachment_fu & update_attributes... bug?
It seems that attachment_fu is a pretty popular plugin (it''s great), but I''ve been having a terrible time trying to figure out an issue when using "update_attributes". I''m storing files on the file system rather than in a database. It seems that when "update_attributes" is called with a new file, upload_data= tries to copy a file that
2006 Oct 05
2
update_attributes
I''m working on a form that updates a product record and several associated detail records. The detail records are showing and populating okay in the form. But when it hits the controller, I get Couldn''t find Detail with ID=detail AND (details.product_id = 38). The :detail params seem to refer to the correct record id. Anyone have an idea how to fix this? Here''s the
2006 Jan 04
0
update_attribute works, update_attributes doesn''t, why?
Hello again... so I narrowed my problem down. For some reason, while using login_generator, any User object I pull from the DB can be updated one attribute at a time using update_attribute, but when I try and do update_attributes it fails every time. Is this a limitation with login_generator that I don''t know about, or is there a way around this? I also tried the .update method and
2013 May 19
5
update_attributes() for a single column
I was just faced with a strange ROLLBACK exception when attempting to execute this code: $ rails console user = User.first User Load (1.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 => #<User id: 1, name: "Michael Hartl", email: "foo-+RB1Aph5k6s@public.gmane.org", created_at: "2013-05-12
2006 May 19
2
update_attributes
My application is so far mostly built from scaffold. When I edit an existing record (I''ve turned off validation) the update method is called. I get this error: NoMethodError in <module>/<controller>#update You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occured while evaluating nil.+ I get the same error when
2012 Sep 20
7
jQueryUI autocomplete (Rails 3.1): can't get source as url to work
Hey, I''m able to duplicate everything in Ryan Bates'' screencast on jQueryUI autocomplete (#102<http://railscasts.com/episodes/102-auto-complete-association-revised>), except for the piece that calls the server for completion data. Here is my view html: <input data-autocomplete-source="/searches" id="search-markets"
2009 Jan 06
2
Update_attributes on multiple models, revert back on error
Hi, I have one method, ''updateStuff'', that will call ''update_attributes'' on 3 different models in the DB..... How can I account for validation to revert back all updates if one of the models is not valid? I''ve looked into Model.valid? which doesn''t seem to work for me .. Any idea? Thanks