Displaying 20 results from an estimated 25 matches for "after_find".
2005 Nov 04
0
after_find callback in an acts_as plugin
Hi,
I am thinking about writing an acts_as_fox plugin that defines an
after_find callback method. If I do this what will happen if a user
creates a model that acts_as_fox but this model has it''s own
after_find callback method? I imagine that the model''s after_find
method shadows the plugin''s after_find. Presumably both after_find
callbacks would need...
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/.
2012 Dec 24
4
Bad idea to add/remove associations in after_find
...#39;'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 way to get around this? I''ve looked at using eval in
after_find to call the has_one, but couldn''t get it working.
Any thoughts?
thanks!
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk-...
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 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 after_in...
2007 Mar 04
4
Rails functional testing and Mocha
...mes.is_a?(Hash) ? method_names :
{ method_names => nil }
method_names.each do |method_name, return_value|
expectations << Mocha::Expectation.new(nil, method_name,
caller).returns(return_value)
end
expectations.last
end
end
Lastly we define an implementation of after_find that causes the
expectations to be set as the objects are loaded
module Mocha
module ExpectationLoader
def after_find
if any = self.class.any_instance_with_id( self.id)
any.expectations.each do |e|
method = stubba_method.new(stubba_object, e.method_name)...
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 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 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 haven''t
had much time to devote...
2006 Oct 08
1
Two-way eager loading?
My problem is that I have two classes where the eager loading isn''t
working as well as I would hope...
Here are my two classes:
class Daynote < ActiveRecord::Base
belongs_to :userplace
class Userplace < ActiveRecord::Base
has_many :daynote, :dependent => true
When I show my userplaces, I want to get the associated daynotes with
them, so I am doing:
@userplace =
2009 Oct 08
6
Eager Loading a Relationship That Has No PK/FK
...How to get around the N+1? select problem and eager load Media?
In the case of Show.all, Show and Media have a relation (yes bad
schema) so I was thinking I could pull all the
Media after a the Segment collection is loaded by Show and assign them
to the Segments accordingly.
But, while there is an after_find, this is applied after each object
and not after the collection.
Any ideas?
Thanks
2007 Mar 18
5
Automatically mocking ActiveRecord methods
Seems like I do a fair amount of mocking ActiveRecord''s automatically
generated routines when I''m testing controllers. Things like:
@portalspace = PortalSpace.new :public_readable => true,
:public_writable => true, :name => ''public''
@portalspace.stubs(:id).returns(203)
PortalSpace.stubs(:find).with(203).returns(@portalspace)
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/.
2006 Jun 27
0
[UPDATE] acts_as_modified 1.1.3 now with tests (was Re: plugin, acts_as_modified 1.1.2)
...And have you run the AR test suite alongside
> this plugin?
>
> -Jonathan.
>
> On 6/27/06, Chris Hall <christopher.k.hall@gmail.com> wrote:
> > 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...
2006 May 15
1
encrypting databases
Hi all, your thoughts appreciated:
I''d like to encrypt one of my databases, as described in the first Rails book,
by putting encrypt and decrypt methods on the :after_find, :before_save, and
:after_save hooks in my model (what a lovely transparent way rails does
things!). But unlike the book, I actually want to use real encryption, perhaps
something from the OpenSSL library, something that requires a symmetric key,
that I will ask the user to enter at login. Either t...
2006 Apr 03
1
Why no call to Model.new on find?
I created a model with some internal state derived from a combination of
database and non-database data. Since I wanted to calculate these values
once rather than every time they''re requested by the view, I calculated
them in the initialize method and set some instance variables. However,
I soon noticed that these values weren''t getting set when I retrieved
data using the
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 May 24
1
Observer behavior differences between DEV and TEST environments ?
...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 GreenbackTransactionObserver < ActiveRecord::Observer
%w( after_find after_initialize before_save after_save
before_create after_create before_update after_update
before_validation after_validation before_validation_on_create
after_validation_on_create
before_validation_on_update after_validation_on_update
before_destroy after_destroy ).each do |meth...
2006 Apr 21
11
Phone Numbers in Rails/MySQL
Is there any easy way to make a fancy looking form to take phone
numbers. Something that looks like this:
[ ] - [ ] - [ ] ext: [ ]
Then when you submit it it''s combined into one string in the database.
Optimally it would auto-switch from field-to-field after you fill each
field.
Has anyone seen anything like this in Rails?
Thanks,
Adam
--
Posted via