I have created a blog, it will have posts, and the posts are created by the users. I already have a login system in my blog. And I have made the relation between a user and his posts. Now when I want to add a new post I want Rails to autofill the user_id field.
Should I add a hidden field and add the user_id from the session where I saved it in?
Or does Ruby on Rails have its own way to deal with relations and using IDs?
@edit:
the model:
class Post < ActiveRecord::Base
validates_presence_of :subject, :body
has_many :comments
belongs_to :user
end
the controller:
....
def new
@post = Post.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @post }
end
end
...