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!
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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?
-- 
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---