similar to: why doesn't this work (setting attribute in "before_create")

Displaying 20 results from an estimated 3000 matches similar to: "why doesn't this work (setting attribute in "before_create")"

2006 Sep 09
13
best way to add "created_by" entries to all tables???
Hi, I want to automate somewhat the addition of created_by/updated_by fields on my models (i.e. to include username). What''s the best/recommended way to do this? Would it be to: a) Find out how to extend the ActiveRecord::Base itself (I haven''t extended a class before yet) b) Use a plugin type approach where you have to add a tag manually to each model file which then
2006 Jan 03
2
help me understand association attributes
I have a model with a belongs_to association. The first model is called Thing and the associated model is User. I''m attempting to assign the user to the thing. To accomplish this I used a before_save method, like this: class Thing < ActiveRecord::Base belongs_to :created_by, :class_name => "User", :foreign_key => "created_by_user_id" def before_create
2006 Mar 26
5
How to write manage created_on and created_by via mixin?
Hi! Definite newbie here - I''m working through this like-hate relationship with Ruby and Rails right now... sometimes things work really well (like blobs seem to rock) but other times, I dunno! :-) Anyway, I''d like put in create and update user timestamps on all my primary domain tables and allow them to be updated automatically by ActiveRecord. Coming from Hibernate, I just
2006 Aug 13
10
does rails enforce referential integrity???
Hi, Is rails supposed to support referential integrity? That is rails either support to be able to ensure that when a new contact is created this can only happen if a valid suberb is associated with it, and which mechanisms of the below are supposed to do this? (a) using DB foreign key constraints information as a basis? (b) using the "has_one" line in the model file to enfore? If
2012 May 26
2
before_create is after_validatation :on => :create , when it should be before_validation :on => :create
In ActiveRecord''s callbacks, methods within a before_create callback are called after the validation, but before the model is created. This was an intentional design decision, but I think it was the wrong one. What do you think? When I think of before_create, I think of before_validation :foo, :on => :create, but, by default, before_create is synonymous with after_validation :foo,
2006 Feb 15
1
self in before_create
Hi, I am having a small problem concernig how to access local variables in before_create. I am not sure how to really form this question but here goes: I am wondering why this works def before_create self.last_logged_in = Time.now self.created = Time.now end but this doesn''t def before_create @last_logged_in = Time.now @created = Time.now end The latter fails
2007 May 05
3
DB trigger vs before_create
Hello everyone, I''m having trouble figuring out which approach is better. I have the following tables: products, orders and line_items. Every time an Order is placed, the quantity field in the products table has to be updated for each LineItem in the Order. One option is to use DB triggers which is not as portable as using before_create in the Order model. But with before_create I cannot
2006 Apr 21
2
Using before_create and conflicting setter method...
Hi, I am having trouble using before_create when I have an specialized setter method: before_save :set_campaign_start #----------------------------------------------------------------------- ------- def set_campaign_start self.campaign_start = Time.now end # We want the date to always start at midnight
2007 Jan 08
2
before_create firing twice on a save - RC2
I have a unit test which fails using Rails 1.2RC2, because a method marked by the before_create filter is firing twice when my ActiveRecord is saved. Is a before_create filter supposed to cause multiple invocations? We have assumed it is called once, and only once, when the object is created, in our code (but we unit tested it to make certain). This is one of three issues I have with my unit
2005 Dec 30
2
before_create question
I have the following models: User, Registration, Event. User has_many Registration, Event has_many Registration, and Registration belongs_to User and Registration. So far, so good. There''s a registration deadline on a Event though, a few days before the Event occurs. So, I have this: class Registration < AR def before_create errors.add_to_base("Registration deadline has
2009 Jun 11
8
before_create return value breaking object.save: rails bug?
I know that usually when people say ''i think i found a bug in rails/ruby'' they''ve done something dumb. I''m wondering if this is the case here, but this does seem like a genuine rails bug to me. In my user model i have a few different before_create callbacks. In one of them, if it happens to return false (just because the last statement in it evaluated to
2006 Dec 06
2
validates_uniqueness_of where scope euqals created_by "magic" field
I have the following ActiveRecord objects: class Recipe < ActiveRecord::Base has_many :ratings, :dependent => true . . . end class Rating < ActiveRecord::Base validates_uniqueness_of :created_by, :scope => :recipe_id belongs_to :recipe, :counter_cache => true . . . end The created_by field on Rating is implemented as a "magic" field similar to this:
2008 Feb 09
0
a problem with before_create and validations
I stumble across some strange problem. I have a model with a virtual attribute file_contents that is a string. The model has validates_format_of :file_contents, :on => create, :unless => no_contents? (The method that returns file_contents.nil?) Then, I have a before_create callback, where I get my model''s title and description by parsing file_contents, and do write_attribute for
2006 Apr 03
3
Retrieving a record using created_by
Hello, Thank you all in advance for your help with this. Environment: Windows XP Pro (Development only) Ruby 1.84 Rails 1.1.0 SaltedHashLoginGenerator Plugins: file_column, userstamp I have a user table per the salted_hash_login generator. I have an orders table that has a column named created_by that is updated by the userstamp plugin. I am trying to retrieve all of the orders for a single
2007 May 27
4
when will "TODO" comment/rake support come out?
Hi - quick question: when will "TODO" comment/rake support come out? Tks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to
2006 Jan 20
11
Userstamp Plugin
I''m pleased to announce a new plugin for Rails: Userstamp. You can read my blog post at http://www.delynnberry.com/articles/2006/01/20/userstamp-plugin and/or read all about it at the perminant page http://www.delynnberry.com/pages/userstamp. Any comments or suggestions for improvement are much appreciated. -- DeLynn Berry delynn@gmail.com http://www.delynnberry.com A dump of the Readme
2007 May 06
5
Comparing polymorphic property to same object fails
I''ve got a polymorphic association on one table. I assign to it in the controller. This is handling invitations of users to tasks in a task management application. If the user issuing the invitation is the user being invited (ie the user assigned themselves to a task), I want to activate the invitation immediately in the model. The trouble is that this: if self.assignable ==
2007 May 20
1
beating a dead horse - proper association selection
okay... i have two models employee - id - username order - id - number - created_by - approved_by now created_by and approved_by are both id''s of employees. in most cases, two different employees. currently i do something like //controller @open_orders = Order.open_orders //model def self.open_orders find(:all, :conditions => [''is_open = ?'', true],
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 Jan 16
16
acts_as_authenticated current_user in a model?
What do I need to do to be able to use an acts_as_authenticated current_user in a model? Is there some sort of include or require I can do some where that would allow this? ********************************************************** Here is what I am trying to do: ********************************************************** class Setting < ActiveRecord::Base before_create :created_by_user #