# Blog and comment

**URL:** <https://www.ruby-forum.com/t/blog-and-comment/184362>\
**Category:** Rails\
**Created:** [March 1, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362 "2010-03-01T14:51:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2010, 2:51pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362/1 "2010-03-01T14:51:21Z")

</div>

Hello everyone,

I’d like to implement a blog on my site.  
I can do this easily enough using the built in scaffolding, and then  
amend it accordingly.

However, I’d quite like users to be able to comment on blogs, and to  
allow for user’s to be stored in the database. In my head I have a  
blogs table with the following columns  
id  
title  
body  
user\_id  
created\_at  
updated\_at

From here, each time i create a blog, the user\_id from the session is  
placed in the table.

All good,

I would quite like the ability for users to then comment on a post  
once logged in.

Has anyone done this. or know of a good tutorial that covers this?

On a side note:  
At present the user\_id is not being set in the blog table. Any reason  
for this???

Many Thanks

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2010, 3:52pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362/2 "2010-03-01T15:52:06Z")

</div>

Craig W. wrote:

> Hello everyone,
> 
> I’d like to implement a blog on my site.

Blogs in Ruby and/or Rails are pretty much the most common sample app,  
if you except the depot application. I’m not sure why you intend on  
reinventing the wheel. If your goal is to have a functional blog, take a  
look at [GitHub - jekyll/jekyll: 🌐 Jekyll is a blog-aware static site generator in Ruby](http://github.com/mojombo/jekyll) or do a quick search for “ruby  
blog” online. If your goal is to develop your skills, …

First, a blog is a collection of posts, so when you say “each time I  
create a blog”, do you mean “each time you create a post” ?  
Secondly, if the user\_id is not being set in the blog table, maybe you  
could show us some code? 🙂

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2010, 5:07pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362/3 "2010-03-01T17:07:08Z")

</div>

An example of relationships between models would be appricated. I am  
trying to use a post and comment system as well and have my models set  
up so a post has\_many :comments and a comment belongs\_to :post. Is  
there any examples for these types of relationships? Im new to ruby  
and just trying to get the basics down.

Thanks,  
Devin M

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 2, 2010, 4:17pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362/4 "2010-03-02T16:17:54Z")

</div>

Thanks! The API has some good examples.

-Devin

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [March 1, 2010, 5:11pm UTC](https://www.ruby-forum.com/t/blog-and-comment/184362/5 "2010-03-01T17:11:48Z")

</div>

Devin M wrote:

> An example of relationships between models would be appricated. I am  
> trying to use a post and comment system as well and have my models set  
> up so a post has\_many :comments and a comment belongs\_to :post. Is  
> there any examples for these types of relationships? Im new to ruby  
> and just trying to get the basics down.
> 
> Thanks,  
> Devin M

Here: [http://railsbrain.com/api/rails-2.3.2/doc/index.html](http://railsbrain.com/api/rails-2.3.2/doc/index.html)  
On the left, enter “has\_many” and take a look at the documentation. It’s  
got a lot of examples-- and if you don’t understand these, then we’ll  
explain them to you 🙂
