Displaying 20 results from an estimated 900 matches similar to: "Something as after_successful_validation?"
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 Apr 10
3
Simple act_as template
Hello !
I posted a simple template to show how to add ''act_as_whatever'' to
ActiveRecord.
I think this might be useful to others as there are some trickery ruby
things in this
file.
Here is the template : http://textsnippets.com/posts/show/384
Gaspard Bucher
--
Posted via http://www.ruby-forum.com/.
2006 Jun 21
1
Plugin Panic! - no accessing a model''s class methods?
Hi plugin-authors.
So this is a little bit of take two on this question, but why can''t I
access a singleton on the model calling my plugin? The crux of the full
plugin below is:
#logger.info self.class.to_s
new_copy = self.class.new( @copyable_attributes )
the logger spits out "Datatype", but I get an error from rails saying:
undefined method `datatype'' for
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`,
2007 Nov 27
1
Plugin - How to access object from instance method
Quick question: Given a basic plugin... how can I access an object that
I instantiated in the acts_as method from an instance method? Probably
some sort of accessor... but where?
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def acts_as_test
object = Object.new ## This object needs to be accessible from the
Instance Methods
end
include
2006 Sep 04
2
"include" versus "extend" - what's the difference
Hi,
Just wondering when one would use "include" over "extend"? Both seem to
bring in methods to the class no?
The context is I''m just trying to understand why both are used with the
acts_as_audited plugin:
Full extract from plugin (used within here):
==================================================
# Copyright (c) 2006 Brandon Keepers
#
# Permission is hereby
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 =>
2011 Oct 14
2
before_save :encrypt_password
I am having a problem finding the best way to make a "before_save
:encrypt_password" conditional.
I have to at times update user model attributes but each time I do this
the password is reencrypted because of the above. I need to
differentiate between when the user is first logging in and the password
does need to be encrypted, and when they are already logged in and the
2008 Jul 10
6
Uppercase all row columns
Hi.
I have to convert the contents of all columns to uppercase before
creating a row. Is there an easy way to accomplish this so I don''t
have to go one column at a time and upcase! it?
Thanks.
Pepe
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group,
2006 Mar 02
2
How to get mime extension with file_column
Is there a way to get the MIME extension of a file_column field?
Here''s what I want to do (look for comment in before_save method):
class ProductFile < ActiveRecord::Base
belongs_to :product
file_column :file_name
def before_save
self.file_type = # something that returns the MIME type (e.g. image/jpeg)
end
end
TIA
2006 Aug 18
4
Default Date storage 0000-00-00?
So I have a database of orders more or less.(it is currently in the
process of being upgraded to mysql with a rails fronted, from OLD
Paradox database) On one page I made a ''create new order'' system. This
allows me to put in the due date and other info. However I wanted to put
in the default value of ''0000-00-00'' for the shipped date, as it hasn''t
2009 Mar 17
4
Preventing a submitted hash from ActiveRecord DB store
Hi all,
I have a multi model form (Project with many tasks) and I want to
prevent a task from being saved to the DB if it is empty ie. if there
is no i/p for that task from the user. I tried the following
class Task < ActiveRecord::Base
before_save :check_if_empty
...
def check_if_empty
self.destroy if description.blank?
end
but i get this
TypeError in ProjectsController#create
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 Feb 10
4
before_save gotcha
Is it will known and accepted that before_save triggers should return
true? I didn''t notice this before but now I see it in the
documentation.
Here is what I''m doing in my model:
def before_save
if self.has_album?
self.visible = self.album.visible?
end
end
That results in the expected result when album.visible? is true - but
not when it is false. To make it
2006 Sep 19
1
Callback sto InstanceMethods in a plugin
Hello there,
I''m currently building a plugin, for which I need a before_save
callback. The method I want to call is in module InstanceMethods, but
when I add a before_save foo, foo, as defined as an InstanceMethod,
never gets called.
This is the first plugin I''m building, after only two weeks of fiddling
with Ruby and Rails, so if anyone is kind enough to help me out.... :)
2006 Jun 26
5
How can I dynamiclly generate models?
I am trying to write a plugin, ''acts_as_commentable'', for my models -
Image, Book, Music and so on, I do not want to use polymorphic
association, so very model should have its own comment class.
Here is my code
acts_as_commentable.rb
module Commentable
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def
2007 Jun 27
3
acts_as_tree and before_save
We all know that acts_as_tree gives us ability to set up data in a
tree-like structure and use methods like ''parent'', ''children'' and so on.
Something I''m completely stuck on. Observe.
class Page < ActiveRecord::Base
acts_as_tree
def before_save
raise self.parent.to_yaml
end
end
Well, you''d think that it should show
2006 Mar 24
2
Access to session data
Greetings,
This, I hope, is a simply answered question.
Based on Agile Web Development with Rails (depot application), I''m
developing a single table application for contact info. There is only
an admin side to this, so there''s always authentication.
Part of the info record (member) is changed_by and changed_at which I
automatically want updated. Changed_at looks after
2006 Jan 25
7
join fields for list views
I am sitting with the Agile book on my desk and scratching my head at
the discussion on aggregation - perhaps that isn''t what I need.
I have a db called clients.
fields include - first_name middle_initial last_name
I want to combine them all into one name element in a list view. I can
add/edit the fields separately but in the list view, I only want the one
combo field.
Is there a