Displaying 20 results from an estimated 10000 matches similar to: "extending an active record model with obj.extend(Module)"
2006 Aug 15
5
Conditional extend of active record
Hi list,
I''m trying to figure out the best way to add some functionality to
active record. I have a table of files, and need to write a set of core
functions that do different things depending on the type of file eg:
class file < ActiveRecord::Base
def resize
....does stuff
end
end
the problem is the "....does stuff". For example, if the file is an
image it
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
2007 Feb 14
4
cache sweeper not getting called
Hi,
I''ve started to implement page caches but I''ve hit a brick wall getting
a sweeper to clear the cache when needed. It seems that any models that
I tell it to observe aren''t being observed properly. If I add the
sweeper to a controller the initialize method runs, but no matter what I
do the after_save/after_update callbacks aren''t running. Also if I try
to
2006 Aug 03
6
create or update -
Hi everyone,
I''m looking for a shortcut to finding and updating or creating record
depending on the results of the find.
So, is there a shorter way to do it than this?
@stuff = Stuff.find_by_foo_and_bar("yay","hooray")
if @stuff: Stuff.update(@stuff.id, {:foo => "boo", :bar => "hoo"})
else Stuff.create({:foo => "boo",
2009 Oct 30
2
polar.plot
Hi,
Two questions:
1 - Say I have average speed and directions for tide and I would like to
plot them on a polar plot, but with different colors so I can indicate the
two directions. I'm using polar.plot from the plotrix library. How can I add
a second "b" and "dir.b" series to a polar.plot?
library(plotrix)
a = 3
dir.a = 85
b = 4
dir.b = 250
polar.plot(a, dir.a, start =
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
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
2003 Mar 05
2
BSOD with ESS under win2000
I have had a visit from our windows buddy the BSOD twice in one day when
running
R1.6.2 under ESS5.1.24 on a win2000 platform. I wasn't doing anything
special, just
moving or resizing the emacs window, although I did have 4 or 5 emacs
windows
open at the time. Has anyone else observed this problem?
Thanks, Darryl.
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 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/.
2006 Jun 01
4
Batch Process for wav->flac?
I have a hard disk full of live shows. Each show is in an individual folder
(titled by name and date of show), and contains the individual wav files of
the show, labeled "disc1track1, disc1track2, etc." It's the same naming
scheme in each of the 200 or so folders for each show.
I want to convert each audio file to flac - is there a way to do this all at
once? I can't just
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
2003 Mar 02
1
model.frame.default problem in function definition
Could someone point me in the right direction for the following issue:
A function is defined as follows:
tfun <- function(dat)
{
fmla <- as.formula("y~x+z")
dat2 <- dat
mdl <- lm(fmla,dat2)
mdl <- step(mdl)
}
Then the following code
dat <- data.frame(x=1:10,z=1:10,y=(1:10)^2+10*(1:10))
tfun(dat)
generates the output
Start: AIC= 43.67
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
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
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
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
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:
2003 Aug 19
3
Out of Office AutoReply: Your application
Salve,
sar? assente dal 18 Agosto al 9 Settembre compreso.
Per importanti escalation utilizzi la coda Clarify EUA_CC NTWKST. Se
desidera parlare col mio manager contatti Alexander Weigl
Cordialmente,
Sandro
------------------------------------------------------------------------
Dear sender,
I'm absent from August 18th till September 9th included. During this time I
wont be able to
2015 Jun 30
2
Re: Issue with virt-builder on Ubuntu 14.04
Rich you're right, I forgot to run make. I added 'set -x' and reran make
and then ran 'virt-builder -v -x' and it seems to hang at dhclient (see
attached log).
Shawn
On Tue, Jun 30, 2015 at 9:17 AM, Richard W.M. Jones <rjones@redhat.com>
wrote:
> On Tue, Jun 30, 2015 at 09:07:25AM -0600, Shawn Greig wrote:
> > - I tried forcing TCG and it gets to the same spot