Displaying 20 results from an estimated 1000 matches similar to: "after_create callback in subclass"
2007 Sep 05
2
after_create callback called twice in test env when using fixtures
All,
I''ve been trying to figure out a strange bug in one of my applications
that I think I''ve narrowed down to a problem with rails fixtures. It
seems as though the after_create callback is being run twice when I
save a record. This is only happening a) in the test environment, and
b) when there is a fixture file for that table.
The test below only prints "Doing
2009 May 25
4
after_create and has_one association bug?
Hello,
I''ve come across an issue that I''m sure is a bug when using after_create
with a has_one association, but I''m not 100% certain if I''m missing
something.
This is pretty much exactly the code I''m using. Two simple classes
(Account and Contact) and I create the contact after I create an account
(via after_create). I''m not passing in a
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 when creating too.
--
cheers,
M.
2006 Aug 14
2
after_create is not being called
Hi all
I have the following model:
class PhotoGallery < ActiveRecord::Base
attr_accessible :title, :description, :file_path, :title_photo_id
has_many :photos, :dependent => :destroy
belongs_to :title_photo,
:class_name => ''Photo'',
:foreign_key => ''title_photo_id''
validates_presence_of :title, :description, :file_path
2006 Aug 17
0
Re Automatically creating associated records with after_create
I don''t get what class Test is for, or where the
registration model is, but remember that registrationS
is the collection object. I think you want something
like
after_create {
self.registrations << Registration.new
}
Cheers,
B Gates
I want to automatically create a registration entry
when I add a new
user to my application. This works fine, but it''s not
2011 Aug 17
0
after_create bug in Rails 3
Hi,
I realized the order of the after_create callback is dependent on where in the class it is defined. I wrote a blog post about it, but am not sure where in the code one might begin to resolve this issue. I''m hoping someone else might be able to help out or guide me in the right direction:
http://ablogaboutcode.com/2011/08/17/after_create-bug-in-rails-3/
Thanks,
Pan
--
You
2007 Feb 24
0
after_create not creating the right object
I have 2 tables... club and forum, which use the "type" as I''m
subclassing the Club and Forum objects. Tables are:
clubs:
id
title
type
forums:
id
club_id
title
type
I''ve put an "after_create" callback in the Club as Club has_one Forum:
class Club < ActiveRecord::Base
after_create :create_forum
has_one :forum
def self.create_forum
# create it
2006 Aug 17
4
Automatically creating associated records with after_create
Hi all.
I am actually using ActiveRecord outside of Rails but I don''t see that
it matters for this question.
I want to automatically create a registration entry when I add a new
user to my application. This works fine, but it''s not automatic:
class User < ActiveRecord :: Base
has_many :registrations
end
class Test
user = User.new
user.registrations.create
end
2009 Jul 21
2
Machinist - having problems stubbing an after_create filter
Hi all
I''m moving to using Machinist in my rspec tests and am having a problem
with an after_create callback method that i need to stub out. It seems
like calling ClassName.make will trigger this callback before i''ve had
the chance to stub it.
Can i stub it in my blueprint for that class? Or, can i stub the method
for all instances of the class before i call ClassName.make?
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 via
2008 Sep 23
3
calling save in after_create hook
Scenario:
I''m creating an image file upload service for my web site.
As well as saving the actual file I also need to create a database
record for the file.
I would like to name the file after the record id, but I also need to
save some attributes of the image (width/height/mime_type etc) which I
can''t discover until after the file is created.
The Problem:
1) The id is not
2010 May 07
1
Apache Tomcat/5.5.23
I have a new instllation of tomcat on centos. My $CATALINA_HOME is
/usr/share/tomcat5 and tomcat is running.
http://localhost:8080 brings up the tomcat page & one of the option is
"Administration". I would like to use this web interface and even give some
of the test webapp users ability to restart tomcat.
According to the home page, users are defined in
2007 Dec 13
16
"Tricks" for testing after_create callback???
I''ve got a model Message, which needs to send an email using action
mailer after it''s first saved in the database.
I want to pass the model to the mailer which then uses methods on the
message model to render the email.
So the natural way to do this is in an after_create callback on the
Message model.
But I can''t see an easy way to test this. Here''s my spec
2006 Mar 01
4
STI, subclasses and callbacks
I have a STI class tree. I want to set some default values (calculated
values so I can''t set it in the database as defaults) on every created
instance regardless of what subclass is actually instantiated. So I
figured adding a after_create callback in the top class in the hierarchy
should do the trick. It seems it doesn''t get called :(
Code:
class SuperClass <
2008 Jul 21
1
Re: Observer
eh, like so?
def after_create(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
def after_update(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
On Jul 21, 9:59 am, David Nguyen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> Hi,
> I have to make an observer if a
2007 Feb 05
1
long jumping out of code in specs
I wrote this abomination just now, and wonder if anyone else has had
experience with the pattern behind it. In short, I''m specing an
after_create hook on an ActiveRecord model, that calls a bunch of
private methods. Instead of stubbing all those private methods (which
is verboten anyway, as well as impossible because creating the object
which owns those methods is what I''m
2008 May 21
1
Callback method for field
Is there callback method for field level?
Generally, after_create and after_save will fire at object level.
I need to fire some code when the value for the field is changed. I need
to call the call back method from observer
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
2009 Jan 27
2
Login form_tag with select_tag option
Hi all,
In the application i develop, a sophisticated login system is required.
Being a newbie in Ruby, i''m not comfortable with the select tag in the
form tag.
My requirement:
2 tables - User(LoginName, Password, RoleId...) and Role(RoleId,
RoleName...)
View - RoleNames to be loaded in the drop down box and On submit, RoleId
to be passed to controller for authentication.
My Code
2006 Apr 06
1
observer doesn''t react
i followed the observer documentation [1] and created, and registered an
observer. i had to realise that the observer doesn''t work at all -- in
fact the rails application does not even start -- with acts_as_taggable,
for whatever reason.
i must admit that i''m still using ruby 1.8.2. however, after commenting
the acts_as_taggable instruction out the application runs smoothly
2006 Jul 19
1
Catch 22 with after_save. Please help.
I have a pretty strange problem. Here is basically what I have to
demonstrate my problem:
class Event < ActiveRecord::Base
def after_create
AnotherClass.find_event(id)
end
end
class AnotherClass < ActiveRecord::Base
def self.find_event(event_id)
e = Event.find event_id
end
end
Here is the catch 22 and it''s quite annoying. Basically ActiveRecord
puts to whole save