این پروژه :
آغاز شده و من هرچی یاد میگیرم رو سعی میکنم توش پیاده کنم تا بشه یک پروژه قابل استفاده و بعضی قسمتاش هم فیلم ضبط میکنم و با بقیه به اشتراک میذارم.
امروز، مشغول پیادهسازی کامنت براش بودم اما وقتی خواستم ریدایرکت به خود پست اصلی رو (به جای این که به صفحه کامنت بره) پیاده کنم، به ارور خوردم.
این کنترلر کامنت منه :
class CommentsController < ApplicationController
before_action :find_post
before_action :set_comment, only: [:show, :edit, :update, :destroy]
before_action :authenticate_user!, except: [:index, :show]
# GET /comments
# GET /comments.json
def index
@comments = Comment.all
end
# GET /comments/1
# GET /comments/1.json
def show
end
# GET /comments/new
def new
@comment = current_user.comments.build
end
# GET /comments/1/edit
def edit
end
# POST /comments
# POST /comments.json
def create
@comment = current_user.comments.build(comment_params)
respond_to do |format|
if @comment.save
format.html { redirect_to @comment, notice: 'Comment was successfully created.' }
format.json { render :show, status: :created, location: @comment }
else
format.html { render :new }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /comments/1
# PATCH/PUT /comments/1.json
def update
respond_to do |format|
if @comment.update(comment_params)
format.html { redirect_to @post, notice: 'Comment was successfully updated.' }
format.json { render :show, status: :ok, location: @comment }
else
format.html { render :edit }
format.json { render json: @comment.errors, status: :unprocessable_entity }
end
end
end
# DELETE /comments/1
# DELETE /comments/1.json
def destroy
@comment.destroy
respond_to do |format|
format.html { redirect_to comments_url, notice: 'Comment was successfully destroyed.' }
format.json { head :no_content }
end
end
private
def find_post
@post = Post.find(params[:post_id])
end
# Use callbacks to share common setup or constraints between actions.
def set_comment
@comment = Comment.find(params[:id])
end
# Only allow a list of trusted parameters through.
def comment_params
params.require(:comment).permit(:body, :user_id, :post_id)
end
end
و این هم خطایی که دریافت میکنم :
در واقع پستی با اون id پیدا نشده، اما هیچایدهای ندارم که چطور اون پست رو درست کنم. ممنون میشم راهنمایی کنید.