Ruby on Rails Thursday, July 1, 2010

On Thu, 2010-07-01 at 21:23 +0200, Jack Fall wrote:
> Hello there,
> I am new around here and have been looking over the internet for a
> solution but can't find one. I am fair new to rails but have a decent
> understanding of it to get by and a few years experience behind me.
> My problem is that I try to insert data in a database and it does not
> come up. The information the user types is inserted however I wish to
> insert the ID and other stuff the user can not change.
> This is what I have so far:
>
> The controller:
>
> def create
> @postform = new(params[:postform])
> @post = Post.new(:title => @postform.title, :body => @postform.body,
> :user_id => session[:user_id]).save
> respond_to do |format|
> if @post.save
> format.html { redirect_to(@post, :notice => 'Post was
> successfully created.') }
> format.xml { render :xml => @post, :status => :created,
> :location => @post }
> else
> format.html { render :action => "new" }
> format.xml { render :xml => @post.errors, :status =>
> :unprocessable_entity }
> end
> end
> end
>
----
def create
@post = Post.new(params[:postform])
@post.user_id = session[:user_id] #assuming you've already
#got this worked out
if @post.save
put your stuff here
end
end


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment