Forum: Ruby on Rails store a session variable in a table

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ishara G. (Guest)
on 2008-11-08 11:28
(Received via mailing list)
i have a session variable called user_id,i want to store
it in a table named blogs
t.column :user_id,
t.column :title,
t.column :body,

i have a form which includes title and
body,i can save them in the table, here is my code

def forum
if request.post? and params[:blog]
@blog = Blog.new(params[:blog])
if @blog.save
flash[:notice]="posted"
else
flash[:error]="not posted"
end
end
end
saideep a.v.s (Guest)
on 2008-11-08 14:21
(Received via mailing list)
Hello ,

add the bold line of code into ur controller (forum) and check.. It
works....

def forum
if request.post? and params[:blog]
@blog = Blog.new(params[:blog])
*@blog.user_id = session[:user_id]*
if @blog.save
flash[:notice]="posted"
else
flash[:error]="not posted"
end
end
end


Thanks & Regards,

Saideep Annadatha


On Sat, Nov 8, 2008 at 2:57 PM, Ishara G. <
This topic is locked and can not be replied to.