search for: after_sav

Displaying 20 results from an estimated 149 matches for "after_sav".

Did you mean: after_save
2009 Mar 29
2
after_create and after_save
Hi, AFAIK after_create is called after_save if the entry does not exist in the DB. Is there a way to tell if a specific model is new or not in after_save? I have to do something like: def after_save add_to_history ''save'' end def after_create add_to_history ''create'' end However after_save is called...
2006 Jul 17
2
Very strange after_save problem. Please help.
I have a very strange problem here. I do not get this. So any help is greatly appreciated. Basically I have a model that calls a method in the background process in the "after_save" method. Let''s call the model products. So what happens is this: 1. I create a new product. 2. Everything works and the product is saved with id 13. 3. A method is called in my background process passing it the NEW product id in the after_save method. 4. That method in the backg...
2006 Jul 17
2
after_save deletes is an exception is raised?
Does after_save in a model delete if an exception is raised in there? I simply did def after_save raise ''hmmm'' end and it raised the exception but there was nothing in the database. I removed that entire method and its in the database. Is this correct? Thank You, Ben Johnson E: bjohnson@c...
2008 Jul 28
1
callback executed like after_save but after transaction
...add some code for my ActiveRecord class so that it is executed whenever an object is updated, this code is a seperate process that reads from the same table represented by my model class so when it runs it needs the database to be up to date. In the following situation this is fine: # MyModel def after_save `/usr/local/bin/update_models -i #{self.id}` end # controller action delete def delete MyModel.find(params[:id]).update_attribute(:deleted_at, Time.now) # after_save is called when the table end But in this situation: # controller action new def new MyModel.transaction do newmodel = M...
2010 May 12
2
How to add an after_save callback on runtime on a particular instance
class User < AR end user = User.new Let''s say that I have a user instance with me. After this record is saved I want an after_save callback which would print the id of the record. The only catch is that I am not allowed to change the User class. How can I accomplish my goal? Is that even possible to add an after_save callback on a particular instance object. Any metaprogramming hack. I''m sure ruby does provide some t...
2009 Jan 18
2
after_save -- stack level too deep
Hi all, I''m running into a brick wall trying to figure out my problem here. I have a model that has a boolean property called "paid". I''d like to add the following to my model: def after_save self.amount == self.splits.sum(:amount) ? self.update_attribute (:paid, true) : self.update_attribute(:paid, false) end The problem is, when I do this I get an error that my stack level is too deep. If I throw this in with one of the model''s validators it works just fine, but that...
2010 Aug 18
11
When after_save isn't after the save....
I have a Production model, which represents a farmer''s crop. After create (via after_save) I call a method that creates one or more Supply models, which represent a week of anticipated product harvest. After each of those are created, a class method gets called that tries to match each new Supply with outstanding orders for the same time period. If a match is made, a transaction (an Ex...
2012 Jan 28
2
after_save in plugin
Dear list, I am trying to override an after_save callback declared in main app using plugin. The main model class is: class WorkHours < ActiveRecord::Base @after_save_call_back_called=0 after_save :after_save_call_back def after_save_call_back logger.debug "after save called" @after_save_call_back_called=1 end end...
2006 May 09
2
handling file upload onto local filesystem.
...asically does something like: profile = Profile.new(params["picture"]) This invokes the models = to method: def picture=(picture_field) ...do a bunch of assignments here end def validate ... do a bunch of validations before saving end # do the actual file handling stuff here. def after_save end My question is, is the after_save method the right place to put the File manipulation stuff to copy and save the file on a directory on my local webserver filesystem? Also, how do I get access to the actual file in the after_save so that I could do stuff like the following: file.local_p...
2006 Jun 01
0
Disabling an after_save() in a rake conversion?
Hi all - I''ve got a model Foo that has an after_save() method. I''d like to disable it while doing a rake conversion. Seems I should be able to just redeclare Foo.after_save() somehow, but I''m not quite sure how to do that in the rake task... Any ideas? Thanks! -philip
2007 Feb 05
0
after_save and associations
It appears that when after_save is triggered, associations such as habtm haven''t been populated yet. Each association can have an :after_add callback, but my code needs to access multiple associations. Is there an explicit reason why after_save isn''t triggered after all of the associations have been populated...
2009 May 28
1
:has_many and :after_save
Having one to many connection (for example post has many comments), what is the most efficient way of saving all comments when post is saved. Using after_save on Post would introduce the n+1 problem. Is there any way of saving the whole structure at once? -- Posted via http://www.ruby-forum.com/.
2010 Jul 28
1
paperclip, authlogic and callback issue
...@current_user_session if defined? (@current_user_session) @current_user_session = UserSession.find end def current_user return @current_user if defined?(@current_user) @current_user = current_user_session && current_user_session.record end and the following after_save callback to regenerate the profile image if the image has changed. after_save do |user| if user.image_changed? Delayed::Job.enqueue ImageJob.new(user.id) end end The current_user method issues a UserSession.find call and Looking at the docs it seems UserSessio...
2012 Jul 07
18
Problem processing text file after uploading
...and docx files to plain text and saves the output to a txt file. My problem is I want to copy the plain text contents of those txt files to the :body field in my database, but by the time those files are written no more changes can be sent to the data base (because all the file handling is done in after_save) Where or how do I sanely get the contents of those TXT files into the database? See model attached: Attachments: http://www.ruby-forum.com/attachment/7574/doc_file.rb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups &qu...
2006 Aug 23
5
validation, concurrency, and transactions
...iqueness constraint, but I''ve heard that this is not the "rails way", and in any case, this is just a simple example. In general the validation code could be arbitrarily complex. The other option that I can see is to use a transaction around the save operation, and define an after_save callback that re-validates the data in the database. If (for the username example above) there is more than one identical username, the after_save callback could throw an exception which (as I understand it) would back out the transaction. Although if this is done, perhaps it is not worth va...
2006 Jul 19
0
save without after_save, after_create, after_update?
How to update attribute(s) and save a record instance without triggering the hooks: after_save, after_create, after_update? I know it''s possible with Record.update() but this is dynamic. Only receive the instance, without knowing its class (thus cannot call the class method update()). Or is there a way of knowing the class and calling the class method? Thank you. -- Posted v...
2006 Mar 21
0
does after_save get called if failed save?
does after_save get called if failed save? Thanks, Chris -- Posted via http://www.ruby-forum.com/.
2007 May 06
3
Using session-type data in an ActiveRecord callback...
Any suggestions on how best to gain access to session-type information while in an ActiveRecord callback, such as after_save? I am encrypting some information in the database, using the generalized encryption/decryption handler in "Agile Web Development With Rails" (p 375ff). I got it working, and now I want to reference a session field (a user PIN) which is NOT stored in the database... for security reasons...
2006 Aug 11
1
after_initialize and after_save
Hello, I am still reading Agile Web Developer pdf, it says about after_initialize and after_find. There is a Joe asks part when I read that they are special, however I didn''t really get the idea, why they are. On rubyonrails.org in the manual there is some sort description about their speciality, however their full descriptions are missing. What are the difference between
2008 Dec 13
3
session In the model
...is SDTicket model has many associated models like Activity one of them So when ever an activity happens then also the value in session[:id] is to be go to modified_by_id field SDTicket has_many activities Activity belongs to SDTicket So for that what I am trying is in Activity model wrote in after_save like below after_save :update_sd_ticket def update_sd_ticket #Here I dont know how to get that session[:id] and fill that to modified_by_id self.service_desk_ticket.save end I also tried like to get session from a module by including it in activity model But that too not working.C...