Web sitemdeki kullanıcıların bir yorumu silmek için bir yol yaratmaya çalışıyorum. Ben hata "[parçaları '' etkin "=? 'Id' = 27]" ile Part bulunamadı" olsun silme bağlantıyı tıkladığınızda buRaylar 'id' ile parça bulunamadı = 27 [WHERE "parts". "Active" =?] PartsNontroller içinde RecordNotFound # Destroy
<li><%= comment.content%> by: <%= comment.user.first_name %> </li>
<% if logged_in? %>
<%=link_to 'delete', part_comment_path(@part, comment), data: {confirm: "Are you sure you want to delete this comment?"}, method: 'DELETE'%>
<%end%>
gibi benim görünümü kurdunuz Parça kontrolörden gelen. Şu anda Yorumlar Yorumlar denetleyici böyle kuruldu.
class CommentsController < ApplicationController
def create
part = Part.find(params[:part_id])
@comment = part.comments.create(comment_params.merge(user: current_user))
respond_to do |format|
format.html {redirect_to part}
format.js{}
end
end
def destroy
@part = Part.find(params[:part_id])
@comment = @part.comments.find(params[:id])
@comment.destroy
format.html {redirect_to part}
format.js{}
end
private
def comment_params
params.require(:comment).permit(:content)
end
end
ve benim Parça kontrolör düzenlenmiştir
resources :parts do
resources :comments, only: [:create, :destroy]
end
Benim modelleri
yuvalanmış yorumlar için buclass PartsController < ApplicationController
before_filter :authorize, :except => [:index, :show]
def index
@parts = Part.all
@categories = Category.all
@parts = @parts.search(params[:search]) if params[:search].present?
end
def new
@part = Part.new
end
def show
@part = Part.find(params[:id])
end
def create
@part = Part.new(part_params)
if @part.save
redirect_to part_path(@part)
end
end
def edit
@part = Part.find(params[:id])
end
def update
@part = Part.find(params[:id])
if @part.update_attributes(part_params)
redirect_to @part
end
end
def destroy
@part = Part.find(params[:id])
@part.destroy
redirect_to parts_path
end
private
def part_params
params.require(:part).permit(:description, :name, :price, :active, :avatar, :discount, :category_id)
end
end
benim güzergah gibi ayarlanır böylece Bölüm ve Bölüm belongs_to Yorum has_many Yorumlar. {Onaylamak: "Eğer istediğinden emin misin bu bir
bu redirect_to @part imha yönteminde – uzaif
deneyin" rake yolları "komutunu çalıştırabilir ve sonucu buraya yapıştırabilirsiniz? ve ayrıca istek için sunucu günlüğü ve yığın izini sağlayabilir misiniz? –
, silebileceğiniz ve söyleyebileceğiniz diğer yorumları deneyin. –