# Attaching user to comment

**URL:** <https://www.ruby-forum.com/t/attaching-user-to-comment/104443>\
**Category:** Rails\
**Created:** [May 18, 2007, 1:37am UTC](https://www.ruby-forum.com/t/attaching-user-to-comment/104443 "2007-05-18T01:37:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 18, 2007, 1:37am UTC](https://www.ruby-forum.com/t/attaching-user-to-comment/104443/1 "2007-05-18T01:37:53Z")

</div>

How would I attach as user to the form input being added into the db?  
User name is defined as @current\_user in application.rb

def comment

@albums = Albums.find(params[:id])  
@albumscomment =  
Albums.find(params[:id]).comments.create(params[:comment])

```
if request.post? and @albumscomment.save
flash[:notice] = 'comment submission succeeded!'
redirect_to :action => 'show', :permalink => @albums.permalink
end

```

end

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [May 18, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/attaching-user-to-comment/104443/2 "2007-05-18T15:22:23Z")

</div>

def comment  
@albums = Albums.find(params[:id])  
@albumscomment =  
Albums.find(params[:id]).comments.create(params[:comment])  
@albumscomment.username = @current\_user  
if request.post? and @albumscomment.save  
flash[:notice] = ‘comment submission succeeded!’  
redirect\_to :action =\> ‘show’, :permalink =\> @albums.permalink  
end  
end
