Displaying 20 results from an estimated 1000 matches similar to: "after_(read|find) callback?"
2006 Feb 19
2
how would you implement this normalizer?
Names of models in my application have accented characters that imply
unexpected orderings. For instance ?vila should go before Madrid, but
String#<=> puts it the other way aroud.
I am only sorting for views, so it would be OK to do some
normalization on-the-fly on Ruby land, and since the same criteria
has to be used throughout the application I was thinking on some sort
of
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 Jan 03
2
Stopping a save from the before_save
What''s the better thing to do in a before_save if you don''t want the
save to continue?
raise an exception, or do an errors.add or both?
Thanks,
Chris Nolan.ca
http://kweschun.com/ - Do you have a Kweschun?
2008 Apr 30
6
best practice for object transaction?
I have a new @offer that needs to generate a document if saved. But
that''s all or nothing:
transaction do
@offer.save!
generate_document
end
# handle exceptions if needed
If save! fails everything is fine, but if generate_document raises an
exception @offer is left as a model with timestamps, id, which is not
a new_record? anymore (though the database was
2006 Aug 01
8
Decoupled observers for controllers?
In the Rails Recipes book the recipe "Keeping track of who did what"
explains how to do decoupled observing of models.
In my application I''d like to do a similar thing but watching the
controllers. For example, when somebody hits the login method of the
Security controller, I''d like to make a note of it. In this case I
could observe the User model and watch for
2007 Jan 04
6
after_update attributes problem
Hey guys,
I''m having a hard time w/ the after_update callback on rails... As
far as I can tell, when I define a after_update callback on a model,
the attributes of the object have the same values that they had
*before* Base.save was called. I''m probably wrong so here''s the code:
UNIT TEST:
def test_register_item_adjusts_account_balance
account =
2007 May 21
7
How do I stop a column being updated by model.save?
One of my models has a column that is updated very frequently from a
separate process, so it is important that when a record is saved in
rails, this column should be left alone. In the update method of the
controller I have:
@record = MyModel.find(params[:id])
@record.update_attributes(params[:my_model])
params[:my_model] doesn''t have a reference to the column I''m talking
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 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
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
2015 Apr 05
3
[LLVMdev] alloca not in first bb behaving differently
Here is some IR that is working and executing as expected -- All allocas
are in the first basic block, and only updates happen in other basic blocks.
define i32 @f() {
entry:
%x = alloca i32
store i32 333, i32* %x
%i = alloca i32
store i32 11, i32* %i
br i1 true, label %if.then, label %if.else
if.then: ; preds = %entry
store i32 3, i32* %i
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
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
2015 Apr 05
2
[LLVMdev] alloca not in first bb behaving differently
It's not great IR, but it doesn't look like it should actually crash, just (without SROA) produce comparatively bad code. The alloca is only referenced in the basic block that it exists. If this isn't expected to work, then we should probably improve the documentation of alloca in the language reference.
David
> On 5 Apr 2015, at 04:55, Eric Christopher <echristo at
2012 Nov 10
6
Suggestion: `before_save on: :create` should either work or raise an exception
There''s a small inconsistency in ActiveRecord''s callback syntax that has
tripped me up before. It wouldn''t be a big deal, but it can lead to a
silent failure. I''d like to suggest that it either be made consistent or be
made to fail loudly.
The issue is that to do something before validating, but only when
creating, you use `before_validation on: :create`,
2006 Nov 17
4
set empty values as null in the database
Le''s say that I have a table called people and the column middle_name is
nullable. If the user enters say blank or empty space then in the database
it is recorded as empty space. I would like in all my models all empty
spaces to be recorded as null.
I guess I can write a plugin which will do so for all the models but I''m
sure something like that should already be existing.I
2006 May 24
7
migrations and SQLite
I read in the instructions of Tracks that "upgrading via the rake
migrate command is quite a bit more tricky currently with SQLite and
SQLite3". Is there any gotcha regarding migrations and SQLite3?
-- fxn
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
2009 Feb 07
5
before_save :strip_whitespace => saves with spaces
i used this private function for removing leading and trailing white
spaces from the values.that below function would be called before_save.
when i print the value after it strips.it prints string without any
spaces.but in the table fields it saves with spaces .
waht would be the problem.pls help me
class CompanyInfo < ActiveRecord::Base
before_save :strip_whitespace
def strip_whitespace
2008 Jun 29
3
Working around/with Restful Authentication
I''m using Restful Authentication, and the code to create a user is
pretty straight forward - there is a before_save action and a
before_create action:
before_save :encrypt_password
before_create :make_activation_code
But for some reason when I try to create a user programmatically in
the controller like this:
User.new(:email =>