REST and CRUD Problem

Hi,

I am trying to make my first application using REST and I am trying to
embrace the CRUD!

However I am coming accross some difficulties.

In my database I have a table called “contents” and this has a
content_type field. So this way I can recognise if it is a blog,
article, event etc. They all share the same structure, so there is not
need to make three tabels.

I first thought that I would need to create three controllers
(articles_controller, blogs_controller and events_controller) to only
use REST/CRUD. However I cannot do this because of the route
defination of map.resources :content

What is the best way to do this using REST ? Have one controller named
content and just check the content_type in the params ? If that is the
case then how would I pass this param value in the url and configure
routes to work nicely ?

Thanks in advance.

Kind Regards
Hamza

Hi,

I have managed to come up with a solution to this problem. However I
am not sure if it is the best way of doing it. Any Help will be
greatly apprciated.

I have made three models. All of the models inherit from the Content
model. So I have this :

class Event < Content
model :content
end

class Article < Content
model :content
end

class Blog < Content
model :content
end

So now with these models I can do this in routes :

map.resources :blogs, :article, :events

I then have three controllers :

blogs_controller
events_controller
articles_controller

So now my application can be CRUD compliant, and it does not require
you to pass a content_type as a parameter.

Is this the best way of doing this ? It seems to me that there is lot
of repitation of code in the controllers. The only real difference
will be a condition of content_type=x

Would it be better in routes to just do this :

map.resource :blogs, :controller=>“content”
map.resource :article, :controller=>“content”
map.resource :events, :controller=>“content”

And then in the content controller somehow look at the url to see where
it is coming from ? How would one do that ?

Thank you in advance.

Kind Regards
Hamza