similar to: extending activerecord base with after_initialize

Displaying 20 results from an estimated 400 matches similar to: "extending activerecord base with after_initialize"

2006 Feb 22
4
UUIDTool and weird timestamp split error
Hi, I am using UUIDTools to generate my Guids. It works fine on my computer (Windows Xp), but doesn''t work on my host (TextDrive) The error is: Loading production environment. >> UUID.timestamp_create.to_s /sbin/ifconfig: Permission denied NoMethodError: private method `split'' called for nil:NilClass from ./script/../config/../config/../lib/uuidtools.rb:236:in
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
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
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
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
2009 May 01
1
how to disable auto-increment in primary key.
How can i disable the auto-increment for a primary key data type. The purpose of using primary_key data type is using different name for primary key. But we still want to use all the properties of "id" except for auto increment part. I had my migration as following #=============MIGRATION def self.up create_table :pk2s , :id=> false do |t| t.primary_key :uid
2006 Mar 02
7
The no-framework PHP MVC framework
"The no-framework PHP MVC framework" http://toys.lerdorf.com/index.php?url=archives/38-The-no-framework-PHP-MVC-framework.html Yuck! What spaghetti code. I can''t ever imagine preferring that to Rails. Joe -- Posted via http://www.ruby-forum.com/.
2006 May 06
0
Issues using GUID plugin: IDs and acts_as_versioned
Hi, First off, I think the GUID plugin is very slick ( http://wiki.rubyonrails.org/rails/pages/Uses+Guid+Plugin). However, I''m running into a few issues: ISSUE #1) Rails'' handling of IDs as strings instead of integers. In particular, it didn''t seem to work when I had a model doing "acts_as_list" with a scope: Example: Class Big < ActiveRecord::Base
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 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
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 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 May 10
2
Exploring ActiveRecord::Base#serialize
Hi I was recently taught about the useful ActiveRecord::Base#serialize. It''s very useful for persisting arbitrary objects through the regular database. For example, say you want to store a Set of all the years a Convention took place. You do: class Convention < ActiveRecord::Base serialize :years, Set end This effectively creates a Convention#years attribute, which is a set: you
2006 Feb 25
1
checkbox helper question
I used scaffolding, then modified. As an after thought I added a "boolean" checkbox to my database, form with this tag <p> <%= check_box ''is_hot_item'', @photo.is_hot_item %> <label for="is_hot_item">hot item?</label><br> </p> I check it and save. But I don''t get 1 saved in my database field. :( I have just the
2006 May 15
8
set_table_name and self.table_name
I have some legacy tables that I used set_table_name on, I''m attempting to write a method that will get key value from a sequence table and then update it and return a value. I''m hoping to put this in the base ActiveRecord method so I would like to reference the table name with self.table_name or something... class Contacts < ActiveRecord::Base set_table_name
2007 Apr 26
0
Shouldn't this spec fail?
Shouldn''t the second spec fail? I''m trying to provide a default value in the model (I''m well aware this is normally the job of the controller, but it seems right to be the model in this case). Also, after_initialize doesn''t seem to be the right way of doing this, but before_create or any of the other things don''t make the first test pass. specify
2007 May 06
0
Initializing a Scheduler
I have a need for a scheduler to run from inside of my rails application. I am familiar with Java (J2EE) and new to Ruby. In Java I would have used a framework called Quartz. I would have created a servlet and in the init method started up the Quartz framework. I have created a new Ruby class and called it StartCron.rb in the Components folder of my Rails app. I have been playing with the
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
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