0
0

More than 1 year has passed since last update.

【Rails】UNKNOWN ACTION ERROR エラーの解決方法。超初歩的なミスだった話

Last updated at Posted at 2022-12-09

エラー内容

  • UNKNOWN ACTION ERROR と表示された。
    ええー初めてみるぞこれ。なんだ!?

原因

  • 超初歩的なミスをしていました。
  • comments_controller.rbの一番上が以下のようになっていました。そう、2行目のendが間違いです!汗
comments_controller.rb
class CommentsController < ApplicationController
end

def create
# 以下省略

解決方法

  • 正しくは以下の通り。endは一番下。アクションはその中に入れるように注意しましょう。
  • controllerの一番上の誤記は盲点で意外と時間がかかってしまったものです。
comments_controller.rb
class CommentsController < ApplicationController


def create
  @comment = Comment.create(comment_params)
if @comment.save
  redirect_to prototype_path(@comment.prototype) 
else
  @prototype = @comment.prototype
  @comments = @prototype.comments
  render "prototypes/show"
end
end

private
  def comment_params
    params.require(:comment).permit(:context).merge(user_id: current_user.id, prototype_id: params[:prototype_id])
  end

  end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0