views:

194

answers:

1

Some of the answers to a question I had about redirect_to made me think about some other questions.

Basically I'm writing a blog application using Rails 2.1. I've been trying to do most of it myself (as I know a bit of rails), but with reference to tutorials and references on the internet when I need it.

I managed to get a simple blog working, then I tried to add comments. By myself I managed to get it to the stage where I could add comments from script/console but I had trouble getting the form to work.

One of the tutorials I followed suggested creating a 'comment' action in the posts controller, which adds the comment. My question is: is that the 'standard' way to do it? One of the answers to my other question seemed to suggest that there should be a CommentsController involved...should there be?

I've managed to fix the problem I asked in my other question, but I'm a little concerned if I'm just making dirty quick hacks rather than programming rails well.

+9  A: 

The preferred Rails approach is now to use a RESTful style, which means that you'd have a Post resource and a Comment resource and yes, that does imply a separate controller for comments.

There's a nice set of articles that explain this over on the Softies on Rails blog that you should find illuminating. Don't let the fact that it's targetted at .NET developers transitioning to Rails put you off!

John Topley
I agree. One small correction: Why does this imply a separate controller? REST refers only to the HTTP interface of the application and to its internal structure...
Christoph Schiessl
Because the Rails' convention is to have a controller per resource.
John Topley