Topic: Models with sessions and params
I have a multi user application. Every user have a unique id number. The users are able to post into a database using the model Post. That works great, except that I can't figure out how to add the user's id number into the database and the :id from the current URL. The user id is stored in session[:user_id]
class Post < ActiveRecord::Base
self.timestamp = Time.now
I use this form:
<%= error_messages_for 'post' %>
<%= start_form_tag :action => 'newpost', :id => params[:id] %>
<%= text_area 'post', 'content', "cols" => 60 %></p>
<%= submit_tag "Create" %>
<%= end_form_tag %>
@post = Post.new
@post = Post.new(@params[:post])
flash['notice'] = 'Post was successfully created.'
redirect_to :action => 'show', :id => params[:id]
How do I set it up so that self.parent will be params[:id] and so that self.user will be session[:user_id]?