Saturday 15 September 2012

ruby on rails - How to do inheritance between models and ActiveRecord::Base? -


I have Rails on Rails and two models using Ruby on the project:

  Class A & lt; ActiveRecord :: Base Attr_accessible: Name Valid: Name ,: Attendance = & gt; True end class B & lt; An Attr_accessible: Age is Valid: Age, Attendance = & gt; True end   

In my a_spec.rb I can see it:

  it should be invalid 'do @ a.should_not be_valid end   

But I can not see this in my B_SPCRB:

  this should be 'invalid' @b.should_not be_valid end   

And I get a fault error:

1) B should have a valid failure / error: @B.Sold_NetB_WalliedNumber Method: Undefined method # code for age '& lt; B Id: zero, name: zero, created_at: zero, updated: zero> '

Anyone can help me fix this? # ./spec/models/b_spec.rb:6:in

Rail generally does not have a relationship like this.

Unless you have a really good reason, all of your models should be inherited from ActiveRecord :: Base

. You can add a table type to the model, You can use a single table succession (STI) for.

On more active records

No comments:

Post a Comment