Displaying 20 results from an estimated 2000 matches similar to: "AR after_initialize quandry"
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
2010 Sep 15
19
Rails 3 with Mongrel possible?
After much fiddling and googling, it seems to me that Mongrel, even the
1.2.0pre2 release is not compatible with Rails 3 -- is that true?
When I start up a new Rails 3 project (i.e. one fresh after a
`rails new` command), mongrel appears to start (creates a pid file, and
reports no errors on the CLI), but the app does not load in the browser
and I find this in the mongrel.log
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 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 Jun 17
1
FYI: Araelium Edit 1.0 Public Preview 1
From: Seth Willits <seth@freaksw.com>
Date: Sat 17 Jun 2006 01:57:52 GMT+02:00
To: Multiple recipients of RealBasic-OffTopic
<rbofftopic@starionhost.net>
Subject: [ANN] Araelium Edit 1.0 Public Preview 1
Reply-To: rbofftopic@starionhost.net
This is what I''ve been doing for a long long time.
----------------------------
Araelium Edit Public Preview Now Available
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
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
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
2006 Aug 15
20
Talking to Java APIs
I''m trying to figure out how Ruby in general, and/or anything extra
Rails may have, can talk to Java APIs of third party server apps.
After quite a few search attempts net-wide and on ruby forums, and
with "Programming Ruby" in hand, I''m coming up with zilch. Either I''m
not finding it, or I''m not recognizing it.
I''m assuming there has
2007 Dec 16
4
Make AR setter methods private?
Hi,
I have a AR model that I want to limit changes to be only via instance
methods that I''ve added.
How do I prevent my other sw from setting the instance''s attributes?
I know about #attr_protected and #attr_readonly. But the first leaves
the individual setters as they were and the second stops all changes.
I want something like "attr_private"
Thoughts?
Thanks,
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
2005 Aug 25
3
Active Record Object Dependency
I have three model objects:
1. Document
2. Section
3. Content
According to my requirements a Document must have at least one Section.
Similarly a Section must have at least one Content.
How can I add a Section when a Document is created and add a Content when a
Section is created?
My code:
class Document < ActiveRecord::Base
has_many :sections
end
class Section < ActiveRecord::Base
2006 Aug 06
2
help with method_missing in ActiveRecord
I am serializing a data object (FooData) into an ActiveRecord column (Foo).
I''d like to be able to do delegate methods to the data class if the Foo
class doesn''t have that attribute. So instead of:
f = Foo.new
f.data.item1
I''d like to do:
f = Foo.new
f.item1
I was hoping that I could add a method_missing method to my Foo class and
call methods in the FooData class
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
2011 Jul 22
0
Asset Pipeline and Sprockets
Ok I would love to work out how to use the new Raisl 3.1 Asset
Pipeline with SCSS variables, mixins etc and being able to use the
asset_path tag.
What I have so far is this. Im my application.css.scss I have the
following.
*= require_self
*= require layout
*= require home
This works fine with using the asset_path helper and variable within
layout ie,
// layout.css.scss.erb
2006 Jun 26
1
plugin, acts_as_modified 1.1.2
After a couple of thoughtful comments, I''ve made changes to
acts_as_modified plugin. It no longer relies on after_find and
after_initialize, which were both causing performance issues.
Please check it out and let me know what you think, where you might
recommend improvements or additional features and what not.
One feature I do have planned (again, thanks to comments), but