Questions tagged [after-save]
68 questions
7
votes
3 answers
rspec testing has_many :through and after_save
I have an (I think) relatively straightforward has_many :through relationship with a join table:
class User < ActiveRecord::Base
has_many :user_following_thing_relationships
has_many :things, :through =>…

dantswain
- 5,427
- 1
- 29
- 37
7
votes
2 answers
How to calculate specific rating count hash in ruby on rails?
So, I have an after_save hook on review model which calls calculate_specific_rating function of product model. The function goes like this:
def calculate_specific_rating
ratings = reviews.reload.all.pluck(:rating)
specific_rating =…

roshita
- 175
- 4
7
votes
3 answers
Rails: check if the model was really saved in after_save
ActiveRecord use to call after_save callback each time save method is called even if the model was not changed and no insert/update query spawned.
This is the default behaviour actually. And that is ok in most cases.
But some of the after_save…

Bogdan Gusiev
- 8,027
- 16
- 61
- 81
5
votes
1 answer
How to know if value changed in Parse Cloud Code afterSave hook?
I want to send push notifications every time the value of a single key of my object changes in a parse cloud code afterSave hook.
Parse.Cloud.afterSave("Channel", function(request) {
var channel = request.object
// TODO: check if value of…

funkenstrahlen
- 3,032
- 2
- 28
- 40
4
votes
4 answers
Rails: Is there an equivalent to save_without_validation which skips after_save filters?
I have an after_save filter which I dont want to trigger in a specific instance. Is there a way to do this similar to save_without_validation?
Thanks,
Jason White
4
votes
1 answer
Rails after_save callback not firing
I have the code below that works just fine for the deletion of record, but on attempting to insert records into the table, using the after_save callback, does nothing.
Essentially what I'm doing is creating a series of advanced relationships that…

Sauron
- 6,399
- 14
- 71
- 136
3
votes
5 answers
How can I invoke the after_save callback when using 'counter_cache'?
I have a model that has counter_cache enabled for an association:
class Post
belongs_to :author, :counter_cache => true
end
class Author
has_many :posts
end
I am also using a cache fragment for each 'author' and I want to expire that cache…

Carter
- 88
- 7
2
votes
2 answers
Rails ActiveRecord using recently saved record id in after_save callback
I want to use recently stored record ID in after_save callback, is that possible if yes how?
after_save :create_children
def create_children
self.id
end
Update:
Sorry there was something going wrong with my save function, my bad, sorry to waste…

wael34218
- 4,860
- 8
- 44
- 62
2
votes
3 answers
Rails 4 Create Associated Object on Save
How can I create multiple associated objects automatically just after I save a new primary object?
For example
In Rails 4, I have three objects: Businesses, Budgets, and Categories.
#app/models/business.rb
class Business < ActiveRecord::Base
…

Ryan
- 10,798
- 11
- 46
- 60
2
votes
3 answers
Check for save after update Rails 4
An update method for one of my controllers looks like this:
def update
@node = Node.find(params[:id])
@video = @node.media
@node.update(node_params)
@video.update(title: @node.name, description: @node.description)
end
I need a callback to…

mike0416
- 461
- 4
- 17
2
votes
1 answer
Cakephp Callback function called multiple times
first some background information:
A user can fill out some input text boxes and upload multiple images (in one upload field). After the form is submitted, the text from the text fields is saved in the DB with $this->XXX->save(). Additionally the…

tobysas
- 308
- 5
- 18
2
votes
1 answer
parse.com inherited ACL + roles - afterSave or beforeSave, tricky scenario
Here's what I am trying to achieve but somehow I am stuck and I am not sure what's the proper approach, I cannot find any good examples of such case so I am seeking your help.
Each registered user can add new object to class "List". Once the new…

lokers
- 2,106
- 2
- 18
- 19
2
votes
1 answer
Save a model instance in afterSave(), won't it run recursive?
I need to sum count some child model data and store it in the parent model instance attribute. But for saving the attribute value I need to call $this->save() or $this->saveAttributes(array(''));
Won't it run save() procedure recursively…

Igor Savinkin
- 5,669
- 8
- 37
- 69
2
votes
3 answers
Undefined method 'column_names' when generating CSV in after_save_filter
I want to generate CSV file after user creates his account, so I created after_save filter in User Model, but I'm getting errors.
Here is my code:
after_save :to_csv
def to_csv(options = {})
require 'csv'
CSV.generate(options) do…

MID
- 1,815
- 4
- 29
- 40
1
vote
2 answers
loopback "after save" trigger both create and update, but I want update only
Product.observe('after save', function(ctx, next){
productHelper.calProduct(ctx.instance);
next();
});
I have above method to do something once a product is updated, but 'after save' is also trigger by create. How can I get trigger only…

Manson
- 37
- 1
- 6