Validating class and superclass on RoR

Posted by Luís Guilherme on Stack Overflow See other posts from Stack Overflow or by Luís Guilherme
Published on 2010-05-18T01:04:00Z Indexed on 2010/05/18 1:10 UTC
Read the original article Hit count: 352

In ruby, you have an attribute called "type" which is the class of the object. Rails stores this at the database in a column called type. So, if I have several blog "types", I can do something like this

def create
  @blog = Blog.new(params[:blog])
  @blog[:type] = params[:blog][:type]
  # ...
end

If I add someone like this, and then load it, and ask its class (for instance, at the console), I have the right class name answered back.

However, when I save it afterwards, rails will run only the superclass validators, not the ones I defined in the subclass.

How should I make rails run the subclass validators?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby