similar to: STI, subclasses and callbacks

Displaying 20 results from an estimated 3000 matches similar to: "STI, subclasses and callbacks"

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 =
2007 Nov 14
4
Interdependency between RSpec files
I run my suite of tests, one test fails. I run that one test file, no tests fail. Something is carrying over between files and I can''t figure out what. I tracked down the problem to the very line it''s occurring on, with printouts before and after every call to make sure I know exactly what is being reached. In this spec I have 0 fixtures/mocks/stubs. The objects in this
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''
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
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
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
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 Mar 15
4
help with DRY violation
I''m trying to be a good rails developer and fix DRY violations as i find them. However, i''m trying to fix this one, i cant seem to get it to work. I have two tables A and B that have a one-to-one relationship. Table B belongs_to Table A. Table A has_one Table B. I''m creating instances of Table A in different places, depending on the controller. However, for each
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
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
2006 Jul 24
9
Mongrel: auto-reload plugins?
When developing applications, Webrick will automatically reload controllers, models, etc. if the source changes. For obvious reasons, it doesn''t do this for plugins, which makes it a pain to develop said plugins. I was hoping Mongrel might have some facility to say "watch this directory too and reload any changes". Obviously, re-init''ing all plugins would be
2011 Dec 02
2
problem setting expectation for test with delayed::job
I''ve got something like this: # post_observer.rb after_create # ...stuff Delayed::Job.enqueue(PostSharer.new(post, post.user)) end ... # post_sharer.rb class PostSharer < Struct.new(:post, user) def perform # Delayed::Job calls .perform on the object passed into enqueue end end # post_controller_spec.rb it "shares the post" do
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
2006 Apr 06
7
LoginSystem : make @session available to models
Hello. LoginSystem is cool, it populates the @session instance variable of controllers with many useful info. The fact is : it would be cool to let models know about the session, too. For instance, after_update and after_create callbacks could store *who* did *what* on *what. Aim : having ActiveRecord::Base::session defined, returning the @session of the controller which manipulates the
2010 May 11
1
has_one/belongs_to -- accessing the subordinate
With a has_one/belongs_to relationship, what''s the best way to guarantee that the belongs_to object gets created and is accessible alongside the has_one object? I *think* the after_create callback is a good choice, but I discovered an oddity while trying it. F''rinstance, if every horse has a carriage: ============ ActiveRecord::Schema.define do create_table(:horses) {|t|
2005 Nov 01
5
Strange error(s) on windows only
I have some strange behaviour on Windows XP boxes (the same code on Linux doesn''t have the same behaviour). Ruby 1.8.2 and Rails 0.14.2. I have a single inheritance table nodes with a base class Node (acts_as_tree) and some subclasses such as PageNode and FolderNode. If I render the tree in an iframe in a set of iframes it doesn''t work, if I render it stand alone it works
2006 Jul 05
2
Serialized object behaves weird
Hi! I got a class named EinsatzFilter which I serialized to session. Before saving to session it works afterwards I keep getting the message: "undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from ActiveRecord::Base inherited class. Code: class EinsatzFilter include ApplicationHelper attr_reader :personen, :monat, :projekte, :kunde
2005 Dec 02
43
ANN: acts_as_ferret
Hi all This week I have worked with Rails and Ferret to test Ferrets (and Lucenes) capabilities. I decided to make a mixin for ActiveRecord as it seemed the simplest possible solution and I ended up making this into a plugin. For more info on Ferret see: http://ferret.davebalmain.com/trac/ The plugin is functional but could easily be refined. Anyway I want to share it with you. Regard it as a