views:

59

answers:

2

Hello,

I'm working on a project where the data model is :

  • implemented in a separate gem
  • does not use ActiveRecord, nor any relational database storage ( actually it relies on couchdb )
  • makes usage of namespaces
  • makes intensive usage of class inheritance

To simplify the schema, let's say we have the following root class :

module Marketplace
 module Food
  class Fruit
  …
  end
 end
end

And a couple of specialized classes :

module Marketplace
 module Food
  class Peach < Marketplace::Food::Fruit
  …
  end

  class Tomato < Marketplace::Food::Fruit
  …
  end
end

end

I'd like Rails to display (and manage) all the Fruits whatever is their nature, without modifying the model witch works perfectly out of Rails.

The issue is that ActionView seems to use a certain number of conventions for defining paths and urls that will be based on the real class names.

So if I present an Apple, in a table with show/delete actions, rails will look for a methods named marketplace_food_apple_path and similar which of course don't exist.

Is there a way to indicate the ActionView::Base structure(s) that an Apple is a Fruit ?

I'd expect this 'base cast' to be 'trivial' for a framework based on Ruby but it seems that this simple example of object oriented model does not work with Rails ?

How do you manage 'complex object' data models in rails ?

Or it is simply out of scope of Rails ?

Thanks for any pointers !

A: 

OK as I see there are plenty of useful answers ;).

It basically confirms my doubts on Rails which I see more like a sort of VB : easy to learn, nice for small things (shopping or community sites) but very limited.

Rails is completely out of scope when it gets to handling complex business logic and data !

As Rails 3.0 does not seem to be the answer neither (ok we have several ORM's but we're still unable to use inheritance in the model) I switched to Ramaze, a small framework that makes no assumptions on how the data is organized making it suitable for almost any kind of web needs.

If you are facing model constraints with Rails, maybe you should forget about Rails and check Ramaze !

devlearn
A: 

http://railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/ <-- probably what you want, unless you're just looking to argue the single inheritance versus multiple inheritance strawman.

corprew
No this is not what I want at all ! I was looking for a way to handle an existing model that uses *class* inhertance in Rails.Seems that this is not possible, nor it will be possible in Rails 3.0. This is a pity and this is why I switched to Ramaze. Module inclusion/extension is a nice feature but does not fit our data model schema at all, mainly because the model already exists and works perfectly our of Rails.So I'm not looking for a way of changing our components to "fit" into Rails, but to use Rails in order to web expose an existing application logic.
devlearn