Skip to content

Instantly share code, notes, and snippets.

View Sporky023's full-sized avatar

Luke Griffiths Sporky023

View GitHub Profile
if @dn_email.confirmation_letter?
VUtility.logged_in_user_id = session[:user].id
@dn_email.job.update_attributes(:confirmation_letter_event_id => @event.id)
redirect_url = "/jobs/#{@dn_email.job_id};edit"
else
redirect_url = "/leads/#{@dn_email.lead_id};show"
end
# change 1
if @dn_email.confirmation_letter?
vdiamond: cap deploy
[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was after_finalize_update)
triggering start callbacks for `deploy'
* executing `multistage:ensure'
*** Defaulting to `staging'
* executing `staging'
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
validates :tag, :uniqueness => {:scope => :post}
validates :tag_id, :uniqueness => {:scope => :post_id}
$ gem install rails -v=3.1.0.rc5
23 gems installed
$ rails -v
Rails 3.1.0.rc5
$ rails new uniqueness_debugging
$ cd uniqueness_debugging/
$ rails generate model post name:string
$ rails generate model tag name:string
$ rails generate model tagging tag:references post:references
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :post
validates :tag, :uniqueness => {:scope => :post}
end
$ rake db:migrate
$ rails console --debug
> p = Post.create(:name => "foo")
=> #<Post id: 1, name: "foo", created_at: "2011-08-11 20:03:12", updated_at: "2011-08-11 20:03:12">
> t = Tag.create(:name => "bar")
=> #<Tag id: 1, name: "bar", created_at: "2011-08-11 20:03:20", updated_at: "2011-08-11 20:03:20">
> tagging = Tagging.create(:post => p, :tag => t)
NoMethodError: undefined method `text?' for nil:NilClass
from ... lib/active_support/whiny_nil.rb:48:in `method_missing'
from ... lib/active_record/validations/uniqueness.rb:57:in `build_relation'
55 def build_relation(klass, table, attribute, value) #:nodoc:
56 debugger; column = klass.columns_hash[attribute.to_s]
57 value = column.limit ? value.to_s.mb_chars[0, column.limit] : value.to_s if column.text?
> tagging = Tagging.create(:post => Post.first, :tag => Tag.first)
(rdb:1) irb
irb(...):001:0> klass
=> Tagging(id: integer, tag_id: integer, post_id: integer, created_at: datetime, updated_at: datetime)
irb(...):002:0> attribute
=> :tag
irb(...):004:0> klass.columns_hash.keys
=> ["id", "tag_id", "post_id", "created_at", "updated_at"]