similar to: before_create return value breaking object.save: rails bug?

Displaying 20 results from an estimated 11000 matches similar to: "before_create return value breaking object.save: rails bug?"

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
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
2005 Dec 29
7
belongs_to causing NoMethodError exceptions ... ?
I''ve got a really strange problem using belongs_to. I apologize in advance for the length... this is going to take a while to explain. Basic idea: Creating a User requires that the user enter an email address and activation key that matches an existing PendingUser. After creating the user successfully, that pending user should be marked as "used". The problem: When I
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,
2008 Nov 03
1
Questions about changes to Restful Authentication.
I have a couple of projects with Restful Authentication The first snippet is from the Git repo today and is supposed to be the newer code. # Store the given user id in the session. def current_user=(new_user) session[:user_id] = new_user ? new_user.id : nil @current_user = new_user || false end # Store the given user id in the session. def current_user=(new_user)
2011 Sep 27
2
passwd problem with new vps
greetings, I am setting up Centos 6 i686 remotely, on a new VPS. A problem I have is that I cannot set password for new users. I have created one with useradd -m new_user but when I type passwd new_user this is the result: [root at vps ~]# passwd new_user Changing password for user new_user New password: Retype new password: passwd: Authentication token manipulation error [root at vps
2006 May 07
1
Overwriting setters for associated objects
Hi all, I''m trying to overwrite a setter method, but am running into some difficulties. This is normally really easy when overwriting a setter for a table column, but in this case it is the setter for an associated object. Here''s a hypothetical example: class User < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :user
2006 Feb 28
1
adding to errors in controller?
def update @product = Product.find(params[:id]) @product.attributes = params[:product] if params[:main_image] image = Image.new params[:main_image] if image.save @product.main_image.destroy if @product.main_image @product.main_image = image else @product.errors.add_to_base(image.errors.full_messages.join(", ")) end end
2006 May 02
1
Custom error messages
On a model I have the following simple validator: def validate unless name && name =~ /^\w+$/ errors.add_to_base("Name is missing") end end I would like to display a custom message on my views, without using the helper <%= error_messages_for "table" %> Where the messages from errors.add_to_base are stored and how to access them in the views? --
2008 Jan 30
2
Where can I get "authenticate_with_http_basic"?
Hi, I just installed Rails 2.0.2 [root@mymachine easyx]# ruby --version ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux] [root@mymachine easyrx]# gem install rails --include-dependencies Need to update 16 gems from http://gems.rubyforge.org ................ complete Successfully installed rails-2.0.2 [root@remandev easyrx]# But I''m getting this error in my restful_authentication
2006 Aug 14
2
after_create is not being called
Hi all I have the following model: class PhotoGallery < ActiveRecord::Base attr_accessible :title, :description, :file_path, :title_photo_id has_many :photos, :dependent => :destroy belongs_to :title_photo, :class_name => ''Photo'', :foreign_key => ''title_photo_id'' validates_presence_of :title, :description, :file_path
2006 May 26
4
Using ''validates_inclusion_of'' to validate foreign key
I seem to be missing something trying to use ''validates_inclusion_of'' to validate a foreign key and was hoping some one could piont out my mistake? The problem seems to be that Order.find_all.collect is not returning an array that contains the order_id, if I replace it with a hardcoded array everything works as expected. The model: class OrderItem < ActiveRecord::Base
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 Jun 24
6
mocking errors
What is the correct way to mock out the errors on a Rails model? I''m assuming i need to say @mock_thing = mock_model(Thing) @mock_thing_errors = mock("errors") @mock_thing_errors.should_receive(:full_messages).and_return("An error") @mock_thing.should_receive(:errors).and_return(@mock_thing_errors) Just wanted to check the best practice on this kind of thing and how
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 Feb 15
8
Agile book - getting confusing error
Working through the beginning phase from the Agile book on ''Administration'' undefined method `hashed_password='' for #<User:0xb7911324> ... /usr/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1498:in `method_missing'' #{RAILS_ROOT}/app/models/user.rb:12:in `before_create''
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
2006 May 19
1
validates_presence_of and ajax-forms
Hi. I have "validates_presence_of :login, :password, :firstname, :lastname" in my user-model. I enter the information in new_user.rhtml: <%= error_messages_for(:user) %> <%= form_remote_tag :url => { :action => :register }, :html => { :id => ''new_user'' } %> I have a register.rjs with :fade. Omitting firstname or any other required field
2006 Sep 09
2
why doesn't this work (setting attribute in "before_create")
Hi, Can anyone spot why the below doesn''t work? * I have a "created_by" column in my create table in the dB * I have a "before_create" line, which definitely gets called * I tried a few different ways to set the "created_by" attribute in the model but it doesn''t seem to work, i.e. doesn''t appear in the database
2006 Aug 09
1
How to Disable Callbacks on a Model
Does anyone know how to disable a model''s callbacks? I have a routine that increments a page_view counter for various model objects in an after_filter in my ApplicationController. I call this: increment_page_view() Rather that checking through the trace array in each model callback for "increment_page_view" I''d rather disable the callbacks from inside