Displaying 20 results from an estimated 1000 matches similar to: "Specify callbacks before associations"
2006 Mar 30
2
Functional test confusion
I have been reading about testing in RoR for what seems like hours now
in search of the answer to what is probably a simple problem. Where is
the best place to test the second action explained below?
I have a controller (NetworkingController) with a method
(create_network_segment) that makes use of two models (NetworkSegment
and NetworkIpaddress). This particular method does two actions:
1.
2008 Jul 21
1
Re: Observer
eh, like so?
def after_create(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
def after_update(model)
generate_hotel_param_files(model.id)
generate_hotel_setup_files(model.id)
end
On Jul 21, 9:59 am, David Nguyen <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> Hi,
> I have to make an observer if a
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 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 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)
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
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 06
4
Using RJS to call custom JavaScript class/method
The announcement for RoR 1.1 shows some nice examples of RJS calls. In
particular I am interested in this one:
# Call the custom JavaScript class/method AddressBook.cancel()
page.address_book.cancel
In trying to develop a "lightbox" style modal form, I have been
successful in saving the form data via AJAX but I can''t seem to close
the "lightbox". I am using the
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
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 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 =
2012 Feb 06
3
Script to automatically update externip. Useful for a host with dynamic public IP
#!/bin/bash
# checksetexternip.sh
# Author: John Cahill email at johncahill.net
# Licence: GPL v3
# Description: script that queries checkip.dyndns.com to find the server's external IP address. Updates asterisk's externip value and does a sip reload if necessary.
# Last modified 06/02/2012
is_ip(){
input=$1
octet1=$(echo $input | cut -d "." -f1)
octet2=$(echo $input
2007 Sep 21
1
Temporary disabling after_update
Hi,
I am trying to replace my old database trigger with ActiveRecord
callbacks in rails.
I have a model like following:
class Action < ActiveRecord::Base
belongs_to :inquiry
def after_update
#clean up all action associated with the inquiry.
Action.update_all("latest = ''''", ["inquiry_id = ?",
self.inquiry_id])
#find the latest action