Displaying 20 results from an estimated 700 matches similar to: "Re: Observer"
2006 Jun 01
0
question about observer callbacks
I''m not sure how to implement this so I''ll describe what I currently have
done then what I wish to have happen
currently, I have a generic observer for several models
class AuditObserver < ActiveRecord::Observer
observe Foo, Bar
def after_update(model)
model.log("UPDATED " + Time.now.strftime("%m-%d-%Y %H:%M"))
end
def after_create(model)
2007 Apr 05
2
best way to maintain dynamic fields?
I have a Topic that has_many comments. In the search results only want
Topics to show up, but I want them to include the text of the comments
that they have when they are indexed. To do this I''ve added a
:comments_text field for acts_as_ferret and the comments_text method
gathers the text from all comments up into a string that can be indexed.
The trick is that when comments are added,
2006 Mar 30
0
Specify callbacks before associations
In the RoR API documentation
(http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) for
callbacks, there is a note that says:
"*IMPORTANT:* In order for inheritance to work for the callback queues,
you must specify the callbacks before specifying the associations.
Otherwise, you might trigger the loading of a child before the parent
has registered the callbacks and they won?t
2006 Jul 19
0
save without after_save, after_create, after_update?
How to update attribute(s) and save a record instance without triggering
the hooks: after_save, after_create, after_update?
I know it''s possible with Record.update() but this is dynamic. Only
receive the instance, without knowing its class (thus cannot call the
class method update()). Or is there a way of knowing the class and
calling the class method?
Thank you.
--
Posted via
2009 Sep 27
1
Switchboard - Easy to use global ActiveRecord event listeners
Switchboard is a simple, event-observing framework for ActiveRecord.
It''s designed to make it easy to add observers for all models in your
app, and to easily turn them on and off selectively.
Intallation
gem sources -a http://gems.github.com
sudo gem install zilkey-switchboard
Usage
First, require switchboard above your rails initializer:
# environment.rb
require
2006 Apr 06
7
LoginSystem : make @session available to models
Hello.
LoginSystem is cool, it populates the @session instance variable of
controllers with many useful info.
The fact is : it would be cool to let models know about the session,
too.
For instance, after_update and after_create callbacks could store *who*
did *what* on *what.
Aim : having ActiveRecord::Base::session defined, returning the @session
of the controller which manipulates the
2007 Feb 09
1
after_update and increment!
I''ve got a strange behaviour that didn''t seem to be happening before I
upgraded to 1.2.
I''ve got two models - questions and results.
When a user answers a question, his answer is recorded in results. In
my results model, I have an after_create that increments! a count in
the question model.
This increment is now triggering an after_update method I have in a
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 16
0
Problems with validates_lenght_of
I''m building a login system, and I want users to be able to update their
password, first name and last name after signing up. So, when signing up
password can''t be nil, and it must be between 6..20 characters long. However,
on update, the user can choose to leave the password field empty (but fill in
other stuff, like first name) and then I want the User model to not update
2006 Oct 25
4
Search result inconsistencies due to indexing
I seem to be having problems with getting my searcher to be consistent
while indexing. I am running the latest version of ferret (0.10.13) and
I am using the Searchable plugin. Currently the way it indexes is by
using a callback in the model of either after_update or after_create to
index the fields that I have setup to be indexed.
Right now I update the index about once every 4 or 5
2006 Jul 18
7
Observer not working
Help please.
I''m trying to observe a User class, but I can''t get this to work, the
after_create method never gets called... (the breakpoint never gets
called)
app/models/user_observer.rb:
class UserObserver < ActiveRecord::Observer
def after_create(user)
breakpoint
setting =
2009 Mar 29
2
after_create and after_save
Hi,
AFAIK after_create is called after_save if the entry does not exist in
the DB.
Is there a way to tell if a specific model is new or not in
after_save?
I have to do something like:
def after_save
add_to_history ''save''
end
def after_create
add_to_history ''create''
end
However after_save is called when creating too.
--
cheers,
M.
2005 Dec 22
1
How to write unit tests with respect to model callbacks?
Hello,
I am exploring the "Testing" part of Rails, but It seems some things
work differently than I thought it would.
Consider the following model:
class Client < ActiveRecord::Base
has_one :project
def after_create
Project.new(:name => self.name, :is_client => true, :client_id
=> self.id).save
end
def after_update
2006 Apr 13
0
Model with file uploads
I''m working on a model for a videos table that include the video info
(title, description) and a couple of uploads (video file, thumb image)
I was going to use the file_column plugin but I dont like the idea of
storing the file names in the database when I dont need to, plus I dont
think it is very flexible.
Here''s what I done. What do you think of this? Any suggestions?
2006 Jan 25
1
cache_sweeper causes undefined method error
I created a sweeper ItemSweeper and saved it in
app/models/item_sweeper.rb. Then I put this in my item_controller.rb:
cache_sweeper :item_sweeper, :only => [:create, :destroy, :update]
But now when I call the view action, I get this error:
ActionView::TemplateError (undefined method `title'' for nil:NilClass) on
line #5 of app/views/item/view.rhtml:
5: <H1
2006 Nov 19
1
ActiveRecord save-update not performed ?
I try to understand the following issue :
- when creating a new User record, I use an UserObserver to trap the
before_save call back and send an email
def after_create(user)
UserNotifier.deliver_signup_notification(user)
end
- Once created a user can ask for a password reset, which is also
trapped by the UserOberver
def after_save(user)
UserNotifier.deliver_reset_password(user) if
2005 Dec 03
0
[Fwd: [Fwd: Problem with setting Normal attribute for a file owned by another user]]
Hi Everyone,
I thought I'd ask again and maybe someone knows the answer..
How come I can read/write to files on a share with any user, but the
"Normal" attribute can only be set by the owner of the file.
Is this by design or am I not setting the right configuration? How is
the "Normal" attribute being handled in Samba?
Thanks,
Oleg.
-------- Original Message --------
2005 Dec 03
0
[Fwd: Problem with setting Normal attribute for a file owned by another user]
Hi Everyone,
I thought I'd ask again and maybe someone knows the answer..
How come I can read/write to files on a share with any user, but the
"Normal" attribute can only be set by the owner of the file.
Is this by design or am I not setting the right configuration? How is
the "Normal" attribute being handled in Samba?
Thanks,
Oleg.
-------- Original Message --------
2013 Oct 22
0
problem while deploying with capistrano-unicorn
Hi,
since today I have some issue when I try to stop / start / restart unicorn
I can''t understand why but it seems to be mixing my local user and my
server user
on config/unicorn/production.rb I have
user ''userserver'', ''userserver''
where ''userserver'' is the name of the user on server
so when I launch command cap unicorn:restart
I
2006 Feb 22
0
How to get model observer to work?
I can''t seem to get a model observer to work. In my environment.rb I
have:
config.active_record.observers = :item_observer
In item_observer.rb I have:
class ItemObserver < ActiveRecord::Observer
observe Item
def after_update(item)
if @old.active != item.active
logger.debug ''observer#after_update''
#...
end
@old = nil
end
def