我不断在messagesController中找不到错误销毁操作。但我有破坏行动设置我不知道为什么我收到此消息错误。有人可以告诉我为什么我会收到这个错误吗?
class MessagesController < ApplicationController
before_action :find_message, only: [:show, :edit, :update, :destroy]
def index
@messages = Message.all.order("created_at DESC")
end
def show
end
def new
@message = Message.new
end
def create
@message = Message.new(message_params)
if @message.save
redirect_to root_path
else
render 'new'
end
def edit
end
def update
if @message.update(message_params)
redirect_to message_path
else
render 'edit'
end
end
def destroy
@message.destroy
redirect_to root_path
end
end
private
def message_params
params.require(:message).permit(:title, :description)
end
def find_message
@message = Message.find(params[:id])
end
end
答案 0 :(得分:3)
您的end
行动错过create
次关闭。正确的方法应该是:
def create
@message = Message.new(message_params)
if @message.save
redirect_to root_path
else
render 'new'
end
end
def edit
end
答案 1 :(得分:0)
您的create
操作缺少end
声明:
def create
@message = Message.new(message_params)
if @message.save
redirect_to root_path
else
render 'new'
end
# This is defined before create is closed
def edit
end