行动“摧毁”#39;找不到MessagesController 1

时间:2016-05-08 10:58:13

标签: ruby-on-rails ruby

我不断在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

2 个答案:

答案 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