This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resources :comments, :articles, :profiles do | |
resources :comments, :only => [:new, :create, :show] | |
has_many :votes | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentsController < ApplicationController | |
before_filter :authenticate, :only => [:create, :edit, :update, :destroy] | |
before_filter :correct_user, :only => [:edit, :update, :destroy] | |
def new | |
@commentable = find_commentable | |
@comment = Comment.new | |
@comment.parent_id = params[:in_reply_to] if params[:in_reply_to] | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There is something wrong with my create method for the comments controller. I get the following error: | |
Couldn't find Comment without an ID. | |
I am trying to pass a hidden parent_id from the comment creation form, so a new comment is formed with that particular parent_id. Here's where the error comes in, I try to do this: | |
@comment_parent = Comment.find(@comment.parent_id), | |
but I get: | |
Couldn't find Comment without an ID. It's weird, because on the error page, it clearly says the following: | |
{"_snowman"=>"☃", | |
"authenticity_token"=>"LJtBKOTojGotLb34xUGzBJR14YvfFhW5tx36EfMHai4=", | |
"comment"=>{"title"=>"hihi", | |
"content"=>"hihi", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Here is the link that leads to the new comment: | |
| <%= link_to "Reply", new_comment_path(:in_reply_to => comment.id) %> | |
My comments_controller#new: | |
def new | |
@commentable = find_commentable # Find Article, Profile if it exists | |
@comment_parent = Comment.find(params[:in_reply_to]) # Find Comment Parent if it exists | |
@comment = Comment.new | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am trying to get threaded comments to work, but I get this error when I try to access my articles page (which has a comments form on the bottom): | |
undefined method `comment_comments_path' for #<#<Class:0xabc1060>:0xabc01ec> | |
Here's the problem code (line 4): | |
1: <div id="comment <%= comment.id %>"> | |
2: <%= comment.title %> | |
3: | <%= link_to "Permalink", polymorphic_path([@commentable, comment]), :action => :show %> | |
4: | <%= link_to "Reply", polymorphic_path([comment, comment.children.new]) %> | |
5: | <%= link_to "Edit Comment", polymorphic_path([@commentable, comment]), :action => :edit %> | |
6: | <%= link_to 'Delete Comment', [[@commentable, comment]], :confirm => "Are you sure?", :method => :delete %><br /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TropicalFishProfiles::Application.routes.draw do | |
get "sessions/new" | |
resources :users | |
resources :sessions, :only => [:new, :create, :destroy] | |
# resources :articles | |
# resources :articles do | |
# resources :comments | |
# end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Problem: | |
I am on the url: | |
http://localhost:3000/articles/297 | |
I have multiple comments on the page with edit buttons beside them. Except, the edit buttons go here: | |
http://localhost:3000/articles/320/comments/297/edit | |
The edit button should be: | |
http://localhost:3000/articles/297/comments/320/edit | |
The id's for the comment and the article pages are reversed! I have posted pages that I find associated with the problem. | |
routes.rb: |