Displaying 20 results from an estimated 5000 matches similar to: "Why no call to Model.new on find?"
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 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 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
2006 Jul 07
4
Calling a method each time an ActiveRecord Object is accessd
Hi,
I know that it is possible to execute code each time data is saved into
a model by using the +validate+ method.
However, is there also a way to execute code each time the data is
accessed, not just when it is changed?
Bye,
Winsmith
--
Posted via http://www.ruby-forum.com/.
2005 Nov 27
1
Comparing field's old value to new value
I want to expire caches if a certain field of an item changes. How can I compare the item field''s
old value to its new value (in the create, or after_save, etc. method)?
thanks
csn
__________________________________
Yahoo! Mail - PC Magazine Editors'' Choice 2005
http://mail.yahoo.com
2006 Jul 05
2
Serialized object behaves weird
Hi!
I got a class named EinsatzFilter which I serialized to session. Before
saving to session it works afterwards I keep getting the message:
"undefined method `to_s'' for #<Person:0x38c6ab8>". "Person" is a from
ActiveRecord::Base inherited class.
Code:
class EinsatzFilter
include ApplicationHelper
attr_reader :personen, :monat, :projekte, :kunde
2006 Aug 16
6
modeling ''phony'' fields.
Hi,
I have a user model with an e-mail field. When a user registers for the
site, I want them to confirm their email address by typing it in again.
If they change their email address, I want them to confirm their email
address by typing it in again. However, the user might change things on
their account not related to their email address, such as their phone
number, and they should not have
2005 Feb 13
5
Select Enumerated Values with FormOptionsHelper
Hey,
I''m new, so apologies if I''ve overlooked obvious resources or violated
any etiquette rules for this list.
Since rails does not support the MySQL enum data type, I''m following
David''s advice of using a varchar and storing the valid values in the
application:
http://one.textdrive.com/pipermail/rails/2005-January/001536.html
So here''s my
2006 Feb 11
5
after_(read|find) callback?
I am pondering the possibility of encrypting/decrypting some fields
in a SQLite backend on-the-fly.
The point of the message is not security, I know that''s broken, but
whether there''s a technique that provides on-the-fly save/read
filters. Of course the solution would need to work transparently in
joins, so
user.posts.last.title
would do the right thing if title
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
2012 Dec 24
4
Bad idea to add/remove associations in after_find
I have 2 distinct types of users (artists and curators) in my system and
they currently share all associations (eg has_one :portfolio).
However, a curator shouldn''t have a portfolio so I would like to only
add that association when required. Obviously I could just return nil
for that method, but it doesn''t feel right having that there in the
first place.
What''s the best
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
2006 Apr 18
12
Formatting data drawn from a DB
Question for all:
Right now i have a Table in a mySQL DB that has a row called
Ingredients. When the data is entered into the DB its enter like so
from a text area:
1 1/2 lbs. beef top sirloin, thinly sliced
1/3 cup white sugar
1/3 cup rice wine vinegar
2 tablespoons frozen OJ concentrate
1 teaspoon salt
1 tablespoon soy sauce
1 cup long grain rice
2 cups water
1/4 cup cornstarch
2 teaspoons
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
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
2006 May 19
7
AR transactions and isolation levels
I''m trying to create a sequence with no gaps in my db (contrived
example, but should work out the same as my real one), and believe
db-managed transactions are the way to go about this.
It''s my first real ''go'' at transactions, so I may be mistaken about
how things really work.
Anyway.. Consider this example code:
Class Invoice < ActiveRecord::Base
def
2002 Feb 05
2
Wine always tries to connect to ":0.0"
Wine always give errors when it tries to start on xser
ver ":1" because it always tries to connect to ":0.0".
I know that DISPLAY is set correctly:
Xlib: connection to ":0.0" refused by server
Xlib: Client is not authorized to connect to Server
2007 May 15
4
Need help with singleton worker
We have a fairly expensive task that we''d rather not schedule too many
instances of in parallel.
Couldn''t get pool_size to limit the amount of workers, and I figure
that''s hardly optimal anyway, so would like to have the work queued up
for a single named worker instead, running as soon as possible.
Using MiddleMan.schedule_worker() with :job_key does start off a
2011 Dec 06
3
Riak on Camping
Good day, does anyone here have a clue on how to make use of the NoSQL
database "Riak" with Camping?
I am building my website and Riak seems like pretty much the ultimate
database!
This would probably ruin every little feature in ActiveRecord, I don''t
think I''d be able to do any has_many''s or belongs_to
but I''d LOVE to be proven wrong. As far as