Comment Form Problem

Hi, I’ve recently implemented permalinks into my app and thus have had
to change all “:id => @post” to use permalinks. However when I got to
updating the comments form I hit a problem, the original code I had was:

<%= form_tag :action => ‘comment’, :id => @post %>

So I thought I should change it to:

<%= form_tag :action => ‘comment’, :permalink => @post.permalink %>

However when I test this by submitting a comment I receive the following
error:

NameError in BlogController#comment

undefined local variable or method `post’ for
#BlogController:0x3423d64

In my blog_controller I have this for comments:

def comment
Post.find_by_permalink(params[:permalink]).comments.create(params[:comment])
flash[:notice] = “Added your comment.”
redirect_to :action => “show”, :permalink => post.permalink
end

Any suggestions would be great!

def comment
Post.find_by_permalink(params[:permalink]).comments.create(params[:comment])
flash[:notice] = “Added your comment.”
redirect_to :action => “show”, :permalink => post.permalink
end

the post variable isn’t defined

redirect_to :action => "show", :permalink => post.permalink

maybe defining it should help:

post=Post.find_by_permalink(params[:permalink])
post.comments.create(params[:comment])
redirect_to :action => "show", :permalink => post.permalink
   # (or even)
redirect_to :action => "show", :permalink => params[:permalink]

no?

No that didn’t work, although now I don’t get an undefined variable
error. Instead it returns to the post page saying “Added your comment”,
but there are no comments shown.

I looked inside the comments table in the database and found that the
comments weren’t being added and that there was a column “post_id”,
however my post don’t have id’s anymore as they use permalinks so I need
the comments to be associated to permalinks.

Any idea how to do that?