Ruby on rails RubyonRails“;行动';创建';找不到MessagesController的;

Ruby on rails RubyonRails“;行动';创建';找不到MessagesController的;,ruby-on-rails,Ruby On Rails,我对RubyonRails路由有一个问题 config/routes.rb: Rails.application.routes.draw do resources :messages root to: 'dashboards#show' end app/controllers/messages_controller.rb: class MessagesController < ApplicationController def index # Do

我对RubyonRails路由有一个问题

config/routes.rb:

Rails.application.routes.draw do

  resources :messages

  root to: 'dashboards#show'

end
app/controllers/messages_controller.rb:

class MessagesController < ApplicationController

    def index
        # Do current user messages select from database here
    end

end
错误:

The action 'create' could not be found for MessagesController

我为什么会有这个问题?我做错了什么?为什么会出现此错误?

您的MessagesController中没有创建方法:

def create
end

您的MessagesController中没有创建方法:

def create
end

您的MessagesController中没有创建方法:

def create
end

您的MessagesController中没有创建方法:

def create
end
默认情况下,该方法不执行post。将路由指定为资源后,它将post映射到#create方法。您需要定义该方法、停止使用帖子或修改routes.rb以将帖子发送到其他方法。从您如何使用它的外观来看,您可能只需修改按钮_以使用get:

<%= button_to 'messages', messages_path, method: :get %>

默认情况下,该方法执行post。将路由指定为资源后,它将post映射到#create方法。您需要定义该方法、停止使用帖子或修改routes.rb以将帖子发送到其他方法。从您如何使用它的外观来看,您可能只需修改按钮_以使用get:

<%= button_to 'messages', messages_path, method: :get %>

默认情况下,该方法执行post。将路由指定为资源后,它将post映射到#create方法。您需要定义该方法、停止使用帖子或修改routes.rb以将帖子发送到其他方法。从您如何使用它的外观来看,您可能只需修改按钮_以使用get:

<%= button_to 'messages', messages_path, method: :get %>

默认情况下,该方法执行post。将路由指定为资源后,它将post映射到#create方法。您需要定义该方法、停止使用帖子或修改routes.rb以将帖子发送到其他方法。从您如何使用它的外观来看,您可能只需修改按钮_以使用get:

<%= button_to 'messages', messages_path, method: :get %>

帮助器()的
按钮的文档说明:

…如果未指定:方法修饰符,它将默认执行POST操作

例如,默认情况下,
button\u to
将以使用POST方法而不是GET方法的形式包装按钮。带有GET请求的
messages\u路径
将转到MessagesController中的index方法,但是带有POST请求的
message\u路径
将被路由到
create
方法。由于没有定义create方法,因此会出现“找不到操作”错误

要解决此问题,请将
按钮的方法设置为
作为GET:

<%= button_to 'messages', messages_path, method: 'GET' %>

帮助器()的
按钮的文档说明:

…如果未指定:方法修饰符,它将默认执行POST操作

例如,默认情况下,
button\u to
将以使用POST方法而不是GET方法的形式包装按钮。带有GET请求的
messages\u路径
将转到MessagesController中的index方法,但是带有POST请求的
message\u路径
将被路由到
create
方法。由于没有定义create方法,因此会出现“找不到操作”错误

要解决此问题,请将
按钮的方法设置为
作为GET:

<%= button_to 'messages', messages_path, method: 'GET' %>

帮助器()的
按钮的文档说明:

…如果未指定:方法修饰符,它将默认执行POST操作

例如,默认情况下,
button\u to
将以使用POST方法而不是GET方法的形式包装按钮。带有GET请求的
messages\u路径
将转到MessagesController中的index方法,但是带有POST请求的
message\u路径
将被路由到
create
方法。由于没有定义create方法,因此会出现“找不到操作”错误

要解决此问题,请将
按钮的方法设置为
作为GET:

<%= button_to 'messages', messages_path, method: 'GET' %>

帮助器()的
按钮的文档说明:

…如果未指定:方法修饰符,它将默认执行POST操作

例如,默认情况下,
button\u to
将以使用POST方法而不是GET方法的形式包装按钮。带有GET请求的
messages\u路径
将转到MessagesController中的index方法,但是带有POST请求的
message\u路径
将被路由到
create
方法。由于没有定义create方法,因此会出现“找不到操作”错误

要解决此问题,请将
按钮的方法设置为
作为GET:

<%= button_to 'messages', messages_path, method: 'GET' %>


如果我不需要它怎么办?当然还有
缺少模板消息/create,application/create with{:locale=>[:en],:formats=>[:html],:variants=>[],:handlers=>[:erb,:builder,:raw,:ruby,:coffee,:jbuilder]}。
如果我不需要它怎么办?当然还有
缺少模板消息/create,application/create with{:locale=>[:en],:formats=>[:html],:variants=>[],:handlers=>[:erb,:builder,:raw,:ruby,:coffee,:jbuilder]}。
如果我不需要它怎么办?当然还有
缺少模板消息/create,应用程序/create,{:locale=>[:en],:formats=>[:html],:variants=>[,:handlers=>[:erb,:builder,:raw,:ruby,:coffee,:jbuilder]}如果我不需要它怎么办?当然还有
缺少模板消息/create,application/create和{:locale=>[:en],:formats=>[:html],:variants=>[],:handlers=>[:erb,:builder,:raw,:ruby,:coffee,:jbuilder]}。