Displaying 20 results from an estimated 121 matches for "after_create".
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...
2006 Aug 17
4
Automatically creating associated records with after_create
...class User < ActiveRecord :: Base
has_many :registrations
end
class Test
user = User.new
user.registrations.create
end
I''d like the User class to do that automatically. I tried this but it
didn''t work:
class User < ActiveRecord :: Base
has_many :registrations
after_create {
self.registrations.create
}
end
I feel like I''m just missing some syntax. Can anyone help?
Thanks!
/adam
--
Posted via http://www.ruby-forum.com/.
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?
--
Posted...
2006 Aug 14
2
after_create is not being called
...ize == 0
errors.add_to_base("There are no files in the directory
#{get_images_path}")
else
errors.add_to_base(images.inspect)
end
end
rescue SystemCallError
errors.add_to_base("The directory #{get_images_path} does not
exist")
end
def after_create
if errors.empty?
get_images.each do |image|
photos.create :file => image.basename
end
end
raise ="asdfasdfasdfa"
end
# some more stuff...
end
When I create a new photo gallery in the console, then after_validation
is being called without any probl...
2008 Jun 03
1
after_create callback in subclass
I have a User model with a protected method defined:
def set_role(rolename)
role = Role.find_by_rolename(rolename)
permission = Permission.new
permission.role = role
permission.user = self
permission.save(false)
end
and a subclass with:
after_create set_role(''client'')
This always fails for me with the error:
undefined method `set_role'' for #<Class:0x2798838>
however, if I call it with a symbol:
after_create :set_role
it finds the method, but fails with a "wrong number of arguments" (as
you wo...
2008 Sep 23
3
calling save in after_create hook
...es 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 available until after the record is saved so I can''t
create the file until after the record has been created
2) if I try to update the record in the after_create hook it creates an
extra record in the database instead of updating the existing one.
Is this a bug?
Any advice to resolve this problem would be most welcome.
It could be done in the controller of course, but I feel it belongs in
the model.
--
Posted via http://www.ruby-forum.com/.
--~--~-----...
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 stuff" one time if I remove the
''fixtures'' line. Likewise, saving the item throug...
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
automatic:
class User < ActiveRecord :: Base
has_many :registrations
end
class Test...
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/afte...
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 (taken from console)
@f = Forum.new(:title => ''Forum'', :club_id => self.id)
@f.save
@f.typ...
2006 Jul 18
7
Observer not working
Help please.
I''m trying to observe a User class, but I can''t get this to work, the
after_create method never gets called... (the breakpoint never gets
called)
app/models/user_observer.rb:
class UserObserver < ActiveRecord::Observer
def after_create(user)
breakpoint
setting = get_setting(''sys_notify_enable_user_create'')...
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 specing, so I don''t have the
object until I call do...
2006 Mar 15
4
help with DRY violation
...ble A has_one Table B. I''m creating instances of
Table A in different places, depending on the controller. However, for each
time i create a Table A instance, i also need to create an empty Table B
instance.
I tried to incorporate this into the model for Table A using various
callbacks, after_create, after_save, before_create. Trying to set the
table_b attribute to a new Table B instance and have table_b''s foreign key
be the id the table_a object being created.
However, i kept running into exceptions "undefined method ''construct_sql''.
I checked my dev log and...
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 http://www.r...
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.g...
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
describe Message, "from anyone" do
it "should be sent on save" do
msg_creation_parms = {
:subject => "Subj",
:body => "hi",...
2006 Oct 27
8
Error after moving to production server
so i have an after_create method on my track model that kicks off a
background process that converts an mp3 to a swf.
this is working fine locally on my machine, but upon moving it to my
production server, i am getting the following error. I''ve only been
using backgroundRB for like 48 hours, so i''m...
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 < ActiveRecord::Base
...
after_create :set_defaults
...
private
def set_defaults
puts "Setting defaults #{id}"
... set values ......
2007 Nov 14
4
Interdependency between RSpec files
...live anywhere outside of the file. This is a model spec and
I''m using all real objects to test it. In the "before" block I set up
some models, and in my spec itself I, in each test, make a couple
changes then call a model''s save method. That model has an
"after_create" method which calls a method in a child model that it
has. It is THIS method which is not being called. I have printouts
before and after everything, like I said, and the lines before and
after the method call work, which leads me to believe that method IS
getting called. However I...