search for: after_initialization

Displaying 20 results from an estimated 50 matches for "after_initialization".

2010 Jun 11
2
AR after_initialize quandry
I have a case where I am abstracting the creation of models. After a fair bit of indirection, I eventually get around to making a .new call. I need to be able to pass params to that .new call. I know I can''t use def initialize() in an AR model (rather frustrating). So, I have found some references to after_initialize, but that doesn''t work either. I see several threads on
2006 Oct 27
5
Purpose of after_initialize in ActiveRecord?
All, I have a quick question - is the purpose of implementing after_initialize to allow custom attribute initialization for AR descendants? I have been overriding initialize whenever I require custom setup of my model classes, like so: def initialize(attributes = nil) super self.Status = ''G'' end So I have a couple of questions: 1) Could I achieve the same
2008 Aug 24
2
config.after_initialize and development mode
Hi, I''m using activemerchant and setting up a class variable using config.after_initialize. It works great for the first request, but then the variable is nil. config.after_initialize do ActiveMerchant::Billing::Base.mode = :test OrderTransaction.gateway = ActiveMerchant::Billing::PaypalGateway.new(...) end I''m assuming this is is due to the model reloading after each
2010 Jan 12
1
Rails after_initialize block doesn't seem to be run in the backgroundrb context
Hi all, Just had an interesting production failure while updating my Rails application - a bunch of code previously in config/environment.rb was put into config/initializers. That resulted in me having to wrap some code in config/environments/production.rb into an after_initialize do ... end block When backgroundrb was run against that code, the setup done in that after_initialize block
2006 Jul 06
2
Custom init. of ActiveRecord objects - best practices
All, I''m wanting to initialize an ActiveRecord object. I understand that there is a method called after_initialize that appears to get called right after the ActiveRecord object is instantiated. Is after_initialize a Ruby thing or a Rails thing? Where is after_initialize documented? Can I pass parameters to it? If so, how? I want to initialize the "belongs_to" attribute of
2006 Aug 11
1
after_initialize and after_save
Hello, I am still reading Agile Web Developer pdf, it says about after_initialize and after_find. There is a Joe asks part when I read that they are special, however I didn''t really get the idea, why they are. On rubyonrails.org in the manual there is some sort description about their speciality, however their full descriptions are missing. What are the difference between
2007 Jun 16
1
extending activerecord base with after_initialize
hi, i am having problems getting after_initialize for activerecord subclasses. basically, i am trying to use the guid plugin by andy singleton. i am having problems extending the class to the plugins i installed, so i figured i will just apply this to all the models in my project. i trled to add the following to my lib/ folder. my goal is to extended the activerecord class so that it uses
2006 May 24
1
Observer behavior differences between DEV and TEST environments ?
Hi all ! I''m having an issue and I can''t seem to make heads or tails of it. I am attempting to add an observer to a model object. I created app/models/greenback_transaction_observer.rb, inherited from AR::Observer, defined methods, registered in config/environment.rb, but things don''t work... So, I took a step back and put in the following code: class
2006 Aug 09
7
function before_save
Hi everybody I would like a function as the "before_save" method in the model. But it must be the opposite. When I take out data from the database through the model, I want to call a function before the data are available in the controller. Can anyone help me? ---- >>>> thx <<<< ---- -- Posted via http://www.ruby-forum.com/.
2009 Jun 24
1
accepts_nested_attributes_for :reject_if issue
I have the following models: class Order < ActiveRecord::Base belongs_to :billing_address belongs_to :shipping_address accepts_nested_attributes_for :billing_address accepts_nested_attributes_for :shipping_address, :reject_if => proc { |attributes| attributes[''has_shipping_address''] != ''1'' } def after_initialize self.build_billing_address
2011 Jun 11
15
after initialize blowing up---help
All, Can anyone see what''s happening here? ================== migration ======================= class CreateGreetings < ActiveRecord::Migration def self.up create_table :greetings do |t| t.string :greet t.string :language t.integer :count t.timestamps end end def self.down drop_table :greetings end end ================== greeting.rb
2011 Apr 27
3
Can't configure cach_store in an initializer
I''m trying to use redis-store as my cache_store. I also have an app_confirg.rb initalizer which loads a yaml file for config settings. In my redis.rb initializer I have: MyApp::Application.config.cache_store = :redis_store, APP_CONFIG[''redis''] However, this doesn''t appear to work. If I do Rails.cache in my rails console I can clearly see it''s using
2006 Jun 26
1
ActiveRecord, instance_eval, and PStore
I''m trying to add some per-object behaviors to objects descended from ActiveRecord, by using after_initialize() and instance_eval(), like this: def after_initialize self.instance_eval(File.read(''customers/default.rb'')) end (Ultimately the file path will be dynamic, this is just proof of concept.) default.rb just contains a few method definitions like this one: def
2006 Jul 11
2
extending an active record model with obj.extend(Module)
Hi everyone, I am trying to extend an active record model using obj.extend(module). The aim is to overwrite some of the model methods depending on what''s in the object. For example, the base class would be "file", with objects such as "image", and "text". The aim is to be able to something like this: file = File.new() file.extend(Image) file.process
2011 Feb 04
6
A plugin inside an engine
In Rails 3, is it possible to have a plugin inside an engine? Adding the lib dir of the plugin to autoload_paths doesn''t seem to work. I can manage to load it by adding that path to $: and requiring the init.rb file, but I''m not sure that''s the correct approach. Thanks! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails:
2007 Apr 24
2
Passing environment to mongrel apps
Hi guys, I''m looking for a way to pass environment variables to my Rails app via Mongrel. I want to conditionally execute code in environment.rb based on these environment variables. Background: 1. I have some special stuff I want to do when my Rails app first starts 2. So, stuff it in environment.rb in after_initialize, right? 3. Not this time. I have several other background
2007 Jul 25
5
set_default_values rocket science - continuing after_initialize/after_find misfeature
Just starting a new thread so that it''s easy to follow. I just submitted a patch at trac to add a new class method called "set_default_values" ( not a great name I think ), which lets you do all kinds of crazy stuff with setting default values. This ticket is at http://dev.rubyonrails.org/ticket/9093 and example pastie is at http://pastie.caboo.se/81925 It also lets you make
2006 Jun 21
3
[PLUG] new plugin, acts_as_modified
Nothing special, just my first plugin. it came out of a request I saw on the list from someone who wanted to be able to tell if a model''s attributes had changed prior to being saved. Well, this plugin does just that (at least I hope it does). http://rubyforge.org/projects/actsasmodified/ Please see the README for details. Constructive comments and criticisms are appreciated. Chris
2006 Feb 24
3
Migrations, data loads and changes to the model
Guys, I''ve run across an interesting scenario with my migrations, and I hope you might share some insight. Let''s say I have 3 migrations and two Models (Person and Car): 001_initial_schema.rb 002_data_load.rb 003_add_car_association.rb The first creates the initial schema...the second loads default data using model objects of Person to do so, and the third creates a new
2010 Nov 09
2
AMQP and Unicorn (mq gem)
Hi all, I''m having issues with Unicorn and connecting to RabbitMQ using the tmm1-amqp gem. I''ve tried lots of approaches. The classic initializer with Thread.new { EM.run } for the Rails app and even tried using the Qusion library. (https://github.com/danielsdeleo/qusion) I''ve made a simple mod to Qusion for it to monkey patch unicorn too. The code looks