ここに私が得ているエラーメッセージがあります
NameError in DiscussionsController#destroy
undefined local variable or method `discussion' for #<DiscussionsController:0x598de20>
私はディスカッションコントローラを作成しました
class DiscussionsController < ApplicationController
def destroy
@discussion = discussion.find(params[:id])
if @discussion.present?
@discussion.destroy
end
redirect_to root_path
end
end
ユーザーが自分のディスカッションを削除できるようにしようとしています。削除を許可するために使用しているビューは次のとおりです。
<% if current_user?(discussion.user) %>
<%= link_to "delete", discussion, method: :delete,
confirm: "You sure?",
title: discussion.content %>
<% end %>
試してみると、http://localhost:3000/disc/7
(7 = Discussion_id) に移動し、そのエラーが表示されます。
私のroutes.dbの一部
resources :discussions, :path => "disc"
どうすればこれを修正できますか? ところで、DiscussionsController は必要ですか? 私はそれを完全に破壊するために作成しただけです。
以下のコメントのエラーの Postcomments テーブル
create_table "postcomments", :force => true do |t|
t.text "content"
t.integer "user_id"
t.integer "micropost_id"
t.timestamp "created_at", :null => false
t.timestamp "updated_at", :null => false
t.text "comment_content"
end
コメント投稿モデル
class Postcomment < ActiveRecord::Base
attr_accessible :comment_content
belongs_to :user
belongs_to :micropost
validates :comment_content, presence: true
validates :user_id, presence: true
validates :micropost_id, presence: true
default_scope order: 'postcomments.created_at ASC'
end