'rails generate controller'不会创建任何文件

时间:2015-06-28 15:05:29

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4 ruby-on-rails-3.2

该命令成功运行,并表示已创建文件,但没有创建文件,再次运行该命令表示它们已存在。

<{1>}之后<{1>},rails generate controller

~/Desktop/Projects/RailsTutorial
create app/controllers/static_pages_controller.rb invoke erb create app/views/static_pages invoke test_unit create test/controllers/static_pages_controller_test.rb invoke helper create app/helpers/static_pages_helper.rb invoke test_unit invoke assets invoke coffee create app/assets/javascripts/static_pages.coffee invoke scss create app/assets/stylesheets/static_pages.scss 上的

ls

~/Desktop/Projects/RailsTutorial/app/controllers

1 个答案:

答案 0 :(得分:0)

您是否在控制器名称后添加了一个方法?要在config / routes.rb中拥有erb视图文件和路由,您还需要使用控制器创建一个方法。

bundle exec rails g controller Recipes index

create  app/controllers/recipes_controller.rb
       route  get 'recipes/index'
      invoke  erb
      create    app/views/recipes
      create    app/views/recipes/index.html.erb
      invoke  test_unit
      create    test/controllers/recipes_controller_test.rb
      invoke  helper
      create    app/helpers/recipes_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/recipes.coffee
      invoke    scss
      create      app/assets/stylesheets/recipes.scss