Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct Rails 2.1 way of doing things

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.

like image 487
robintw Avatar asked Oct 22 '08 06:10

robintw


1 Answers

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!

like image 188
John Topley Avatar answered Sep 29 '22 21:09

John Topley