# Set table value

**URL:** <https://www.ruby-forum.com/t/set-table-value/194805>\
**Category:** Rails\
**Created:** [September 11, 2010, 4:18am UTC](https://www.ruby-forum.com/t/set-table-value/194805 "2010-09-11T04:18:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evanoshkithegreat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@evanoshkithegreat](https://www.ruby-forum.com/u/evanoshkithegreat)\
**Post date:** [September 11, 2010, 4:18am UTC](https://www.ruby-forum.com/t/set-table-value/194805/1 "2010-09-11T04:18:46Z")

</div>

Hi guys,

I’m a newbie in ruby and I would just like to know how you set a value  
for a field in a table where session[:user\_id] matches user.user\_id.

I am trying to do this from a submit form in the show.html.erb file  
because that is where the other field value is set.

Help would be much appreciated…

**Title:** \<%=h @post.title %\>

**Mood:** \<%=h @post.mood %\>

**Location:** \<%=h @post.location %\>

**Thoughts:** \<%=h @post.thoughts %\>

#### Comments

 \<% @post.comments.each do |comment| %\> - \<%= h comment.comment %\>  

 Posted on \<%= comment.created\_at.strftime("%B %d, %Y at %I:%M %p")%\> 

\<% end %\>

\<% form\_for(:comment, :url =\> post\_comments\_path(@post)) do |f| %\>

Comment:  
 \<%= f.text\_area :comment %\>

 \<%= comment.username.set("User.find\_by\_id(session[:user\_id]).name") %\> \<%= f.submit "Create" %\> \<%end %\>

\<%= link\_to ‘Edit’, edit\_post\_path(@post) %\> |  
\<%= link\_to ‘Back’, posts\_path %\>

---

<div class="post-metadata">

**Author:** ![evanoshkithegreat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@evanoshkithegreat](https://www.ruby-forum.com/u/evanoshkithegreat)\
**Post date:** [September 11, 2010, 10:34am UTC](https://www.ruby-forum.com/t/set-table-value/194805/2 "2010-09-11T10:34:06Z")

</div>

On Sep 11, 3:18 am, Evanoshki Brataslavainskinski \<li…@ruby-  
[forum.com](http://forum.com)\> wrote:

> Hi guys,
> 
> I’m a newbie in ruby and I would just like to know how you set a value  
> for a field in a table where session[:user\_id] matches user.user\_id.
> 
> I am trying to do this from a submit form in the show.html.erb file  
> because that is where the other field value is set.

If I’ve understood you properly you’re doing this back to front. You’d  
typically do this in the comments controller, when you are creating  
the new comment

---

<div class="post-metadata">

**Author:** ![evanoshkithegreat](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/edb3f5/32.png) [@evanoshkithegreat](https://www.ruby-forum.com/u/evanoshkithegreat)\
**Post date:** [September 11, 2010, 7:10pm UTC](https://www.ruby-forum.com/t/set-table-value/194805/3 "2010-09-11T19:10:18Z")

</div>

is user.id no user.user\_id

On Sat, Sep 11, 2010 at 4:33 AM, Frederick C. \<
