Hello all,
I am implementing tagging on my site. The problem I am experiencing is
that when I apply tags to a Blog model object, if one of the tags is
invalid, it doesn''t raise any type of error in the blog model...it just
silently fails. Here''s what my models look like.
class Blog < ActiveRecord::Base
has_many :taggings, :as => :taggable
has_many :tags, :through => :taggings
end
class Tag < ActiveRecord::Base
has_many :taggings
validates_format_of :name, :with => /^[a-zA-Z0-9]*$/, :message =>
"Invalid characters in tag."
def on(taggable)
tagging = taggings.create :taggable => taggable
end
end
class Tagging < ActiveRecord::Base
belongs_to :tag
belongs_to :blog
belongs_to :taggable, :polymorphic => true
def self.tagged_class(taggable)
ActiveRecord::Base.send(:class_name_of_active_record_descendant,
taggable.class).to_s
end
def self.find_taggable(tagged_class, tagged_id)
tagged_class.constantize.find(tagged_id)
end
end
Here''s what my controller test code looks like to simulate the
condition.
def test
blog = Blog.find(:first)
blog.tag_with("in--@idtag")
raise blog.valid?.inspect # => true, but I want it to be false
end
This is driving me batty and it''s probably just something simple, but 2
hours of research didn''t pull anything up. Thanks ahead of time if
anyone can point me in the right direction.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---