similar to: ActiveRecord object.valid? triggers unexepected results

Displaying 20 results from an estimated 300 matches similar to: "ActiveRecord object.valid? triggers unexepected results"

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
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 Mar 13
3
validates_associated problem
Hello, I have a situation where an ''employee'' belongs to a ''department'' and have setup the relationship as follows. class Employee < ActiveRecord::Base belongs_to :department, :foregin_key => "department_id" validates_associated :department_id end class Department < ActiveRecord::Base has_many :employees def validate_on_update
2006 May 08
6
how to make field in model immutable after create
Hello everyone! I want to have login field in User model which is set only once (on create), and then it should fail validation if the value is changed. How can I do this? I dig around for validation and tried def after_validation_on_update unless User.find_by_login(:login) errors.add(:login, "is immutable. You can''t change it") end end in model, but somewhat it
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
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 Mar 31
10
ruby help / if (cond or cond)
Why this code doesn''t work as expected? It raises exceptions everytime. Tried with || operator, too. validates_each :x, :y do |record, attr| record.errors.add (attr, ''between 1 and 100'') if (attr.to_i>100 or attr.to_i<0) end -- They say money can''t buy happiness? Look at the smile on my face... ear to ear, baby!
2006 Jun 21
1
Migration with foreign key won''t work
Hi all I use the plugin which supports foreign keys with migrations: http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin/versions/12 I have created the following migration file: class AddArtistsTable < ActiveRecord::Migration def self.up create_table :artists, :force => true do |t| t.column :name, :string, :limit => 100 t.column :artist_type_id,
2012 Jun 04
4
Driver for a REDi Blazer 600VA UPS
I'm running NUT 2.6.3 on Debian wheezy [ with a 3.3.0 i686 kernel ] I've installed NUT via Debian APT [ package nut version 2.6.3-1 ] I have a REDi Blazer 600VA (BLAZER600c) UPS and I want to detect power failures. I have tried the following drivers: * gamatronic: Can't talk to UPS on port /dev/ttyS1! * bestups: Unable to detect a Best/SOLA or Phoenix protocol UPS * blazer_ser: No
2006 Feb 22
0
STI and Inheritance
Hello ~ I have run into an issue with some of my objects not behaving as I expect. Basically I am using STI on my Users table and have several types of users. BaseUser --UserType1 < BaseUser --UserType2 < BaseUser etc.... Recently when I create a UserType object and save it to the database it ignores the validation rules for the parent class BaseUser. Furthermore the after_validation
2007 Jan 04
6
after_update attributes problem
Hey guys, I''m having a hard time w/ the after_update callback on rails... As far as I can tell, when I define a after_update callback on a model, the attributes of the object have the same values that they had *before* Base.save was called. I''m probably wrong so here''s the code: UNIT TEST: def test_register_item_adjusts_account_balance account =
2006 Jul 30
0
after_validation_on_update double invokes
Hello to all, I want to use the after_validation_on_update call back to keep some redundancy in sync with the model. But now I''ve encountered that the call-back get called two times. Is this the intended behaviour? What can I do to prevent Rails from doing so? best regards Torsten
2012 Jun 09
3
[HCL] REDi/Centralion Blazer 600 VA (BLAZER600c) supported by blazer_ser
The REDi Blazer 600VA (BLAZER600c) UPS found here [ro_RO]: http://www.emag.ro/ups-redi-blazer-600va-blazer600c/pd/EX5X2BBBM/ which is actually a Centralion Blazer 600VA [en_TW]: http://www.centralion.com/html/product/back-Product-ups-blazer400.htm works with the blazer_ser driver ----------shell output---------- # upsrw ups # upscmd -l ups Instant commands supported on UPS [ups]: beeper.toggle -
2007 Feb 25
5
Dynamically uploading a list that's already in a form
I have the classic case of: Posts, and Categories. When the user submits a post, he has a drop-down list of categories. I want to put a "Add category" link next to the list of categories. This is already inside a form, so a "link_to_remote" that creates a small AJAX form inside the "submit post" form will not work because that will mean to embed a form in another
2010 Jul 08
3
my web app seed data and cucumber
I''m writing a web app which is used a SaS. Each customer has their own db and app directory. I have a rake task which creates all necessary minimum data to run their website: default rights and roles, a superadmin user, a "us_states" table already populated, some local depots and terminals (it''s a logistics app). I don''t have any cucumber scenarios for it and
2009 Apr 06
3
After Rails 2.3.2 upgrade: superclass mismatch for class TestCase (TypeError)
I upgraded a working app from rails 2.1 to 2.3.2. Now when I run rake test:units I get this error: /usr/lib/ruby/gems/1.8/gems/ activesupport-2.3.2/lib/active_support/test_case.rb:17: superclass mismatch for class TestCase (TypeError) I generated a new test app and all tests run OK. For the upgrade I ran rake:update and renamed the class in test_helper to ActiveSupport::TestCase. Also renamed
2007 Feb 09
1
after_update and increment!
I''ve got a strange behaviour that didn''t seem to be happening before I upgraded to 1.2. I''ve got two models - questions and results. When a user answers a question, his answer is recorded in results. In my results model, I have an after_create that increments! a count in the question model. This increment is now triggering an after_update method I have in a
2006 May 21
0
expiring cache fragments using script/runner
I''ve just set up caching on my site and want to expire some of fragments on an hourly basis. I was going to use cron and script/runner to do this. For other fragments that I am expiring, I am using expire_fragment inside a sweeper class, something like: class QuestionSweeper < ActionController::Caching::Sweeper observe Question def after_validation_on_update(question)
2010 Aug 14
0
How do I unit test this?
I''ve got a cache sweeper running observing a model "after_validation_on_update". Inside that filter method, a call to "controller.current_user" is made to access that application_controller method (to get the current user in session). I get the error "NoMethodError: undefined method `current_user'' for nil:NilClass" when running my unit test
2006 Jun 09
0
difference between @secure_password, secure_password
Hello, I have a User object that extends ActiveRecord::Base. And I have the following defined in it: .... after_validation :crypt_password ... def crypt_password # write_attribute("secure_password", User.encrypt(password)) self.secure_password = User.encrypt(password) end .. And this works. Where I am getting confused about is the difference between the following: