similar to: function before_save

Displaying 20 results from an estimated 1000 matches similar to: "function before_save"

2006 Aug 14
3
last record
hi @all Can anyone help me? I would like to read the last two records from a database. In the database I have a table with id, name and sex. How can I read the last two records from the entered names, who are female? There are two conditions I need: > last entries > sex-condition User.find(:all, :condition.....) ?? -- Posted via http://www.ruby-forum.com/.
2006 Aug 17
3
Use collection_select
I use the following code in my view: <%= collection_select(''datedata'', ''date'', @allDate, :id, :date) %> It''s show me the date of all entries in the database (Dropdown menu). Additional, I wrote a helper method "showDate" in the application_helper.rb! How can I use this method in the collection_select for every date entry? thanks
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
2006 Aug 03
2
Link to an other model
Hi I a newbie in RoR! So I have an easy question for some of you: I want with the following codeline link to the Admin-Controller. The codeline is on the Product-View with a seperate controller "Product". <%= link_to ''Back'', :action => ''Admin'' %> But it doesn''t work correctly. Can anyone help me? I want to make a simple link!
2006 Aug 08
2
validate data
Can anyone help me?? I validate a form-field: protected def validate errors.add(:name, "should be longer than 2 chars") unless name.length <= 2 end I want to check the variable name. It should have a size over 2 characters. But my function "validate" doesn''t run! Why ??? -- Posted via http://www.ruby-forum.com/.
2006 Jun 26
1
plugin, acts_as_modified 1.1.2
After a couple of thoughtful comments, I''ve made changes to acts_as_modified plugin. It no longer relies on after_find and after_initialize, which were both causing performance issues. Please check it out and let me know what you think, where you might recommend improvements or additional features and what not. One feature I do have planned (again, thanks to comments), but
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 Jul 06
2
Custom init. of ActiveRecord objects - best practices
All, I''m wanting to initialize an ActiveRecord object. I understand that there is a method called after_initialize that appears to get called right after the ActiveRecord object is instantiated. Is after_initialize a Ruby thing or a Rails thing? Where is after_initialize documented? Can I pass parameters to it? If so, how? I want to initialize the "belongs_to" attribute of
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 Jul 07
4
Calling a method each time an ActiveRecord Object is accessd
Hi, I know that it is possible to execute code each time data is saved into a model by using the +validate+ method. However, is there also a way to execute code each time the data is accessed, not just when it is changed? Bye, Winsmith -- Posted via http://www.ruby-forum.com/.
2006 Apr 03
1
Why no call to Model.new on find?
I created a model with some internal state derived from a combination of database and non-database data. Since I wanted to calculate these values once rather than every time they''re requested by the view, I calculated them in the initialize method and set some instance variables. However, I soon noticed that these values weren''t getting set when I retrieved data using the
2005 Nov 27
1
Comparing field's old value to new value
I want to expire caches if a certain field of an item changes. How can I compare the item field''s old value to its new value (in the create, or after_save, etc. method)? thanks csn __________________________________ Yahoo! Mail - PC Magazine Editors'' Choice 2005 http://mail.yahoo.com
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
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
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
2008 Aug 24
2
config.after_initialize and development mode
Hi, I''m using activemerchant and setting up a class variable using config.after_initialize. It works great for the first request, but then the variable is nil. config.after_initialize do ActiveMerchant::Billing::Base.mode = :test OrderTransaction.gateway = ActiveMerchant::Billing::PaypalGateway.new(...) end I''m assuming this is is due to the model reloading after each
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
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?
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