search for: before_saves

Displaying 20 results from an estimated 177 matches for "before_saves".

Did you mean: before_save
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`,
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
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
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
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
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 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 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 =>
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
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,
2007 Dec 26
0
before_save with acts_as_versioned
Yes, I know about the :if/:if_changed clause on acts_as_versioned ... content_changed or author_changed .... That''s not what I''m asking about. What I''m wondering about is something like applying the spiffy new 2.0 sanitize as a ''before_save'' -- A little inaccuracy can save tons of explanation. -- Saki
2009 Oct 23
0
Sanitize html with :before_save depending on logged in user
I woud like to sanitize attributes (with ''sanitize" gem) but unless the model is being saved by admin. (Suppose this model doesn''t have any relationship with user model) # In model.rb: :before_save set_html_plain def set_html_plain self.body = Sanitize.clean(self.body) end Two questions: 1) How can I check here if saving process has been initialized by
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 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 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 Jul 17
5
Keeping attributes of two models in sync
Hi, I have a Product and a corresponding Keyword (1:1 via belongs_to and has_one). I want to ensure, that two attributes (:name) of the two models alway stay in sync. What''s the easiest way to accomplish that? I did play around with before_/after_save hooks and with AR::Observers but in the end I''d always get infinite recursion... Thanks, Timo
2006 Jun 24
0
before_save and before_update not being called in tests
In one of the models I perform some operation. For simplicity let''s assume that I populate column ''b'' with column ''a'' * 2. def before_update self.b = self.a * 2 end In my fixture I set values for a. first: id: 1 a: 10 Whe I run the test before_update is never invoked when rails populate the test table with the data from fixture. In
2006 Apr 08
4
Calling validates_inclusion_of out of default namespace
Hi, I''m trying to run the "validates_inclusion_of" method in a before_save hook, because the range is dependant on the related data. But I can''t figure out how to call it. When calling it normally, it says it can''t find it. I''ve tried several combinations like "ActiveRecord::Validations.validates_inclusion_of", but I can''t seem to
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