ActionNotFound(无法为CompaniesController找到操作'index'):

时间:2015-04-27 20:05:25

标签: ruby-on-rails

我运行了一个webrick,shell显示了这个错误

AbstractController::ActionNotFound (The action 'index' could not be found for CompaniesController): 

有我的routes.rb

  resources :companies do
    member do
      put :click_on
    end
    get :generator, on: :collection
  end
  root 'welcome#welcome_page'

控制器没有index动作

如何解决?

1 个答案:

答案 0 :(得分:2)

index操作(这只是一种方法)添加到您的控制器,如错误消息所示:

class CompaniesController < ApplicationController
  def index
  end
end

然后将视图添加到渲染:

<%# app/views/companies/index.html.erb %>
<h1>Companies Index</h1>

阅读Rails documentation,了解有关控制器基础知识如何工作的更多信息。