views:

109

answers:

2

Currently I have this:

class Group < ActiveRecord::Base

   delegate :publish_group_creation, :to => 'MyAppModules::Publisher'  
   after_create :publish_group_creation

end

The thing is that Publisher.publish_group_creation receives 1 argument (the group that's gonna be published)

I tried something like this;

delegate :publish_group_creation, :to => 'MyAppModules::Publisher', :group => self

but it doesn't work, what is right way to pass parameters using delegate ?

A: 

Hi, I'm not sure if this will work for your scenario, but you might try reworking this a bit. Something like

module MyAppModules::Publisher
  def publish_group_creation
    ...
  end
end

class Group < ActiveRecord::Base

  include MyAppModules::Publisher

  after_create :publish_group_creation

end
Mike
A: 

Methods called via callbacks don't receive parameters in Rails.

Try this:

class Group < ActiveRecord::Base
  after_create :publish_group

  private
  def publish_group
    MyAppModules::Publisher.publish_group_creation(self)
  end
end
PreciousBodilyFluids
If the Publisher module's methods will all apply to your Group model, then you'll want to go with Mike's answer. I was assuming that Group and Publisher were mostly unrelated.
PreciousBodilyFluids
Thanks, that's how currently is my code, that would be nice if we could pass 'em inline!
jpemberthy