脚手架 Rails4 空控制器 [英] Scaffolding Rails4 Empty Controller

查看:51
本文介绍了脚手架 Rails4 空控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 testapp 项目中使用了多个脚手架.

I'm using multiple scaffolding in my testapp project.

我已经创建了这样的第一个脚手架:

i have created 1st scaffold like this:

rails g 帖子标题 desc:text

它成功并创建了所有相关文件和控制器.

it was successful and created all relevant files and controller as well.

但是当我制作另一个脚手架时:

but when i made another scaffold :

testapp$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean
      invoke  active_record
      create    db/migrate/20140513062549_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/models/product_test.rb
      create      test/fixtures/products.yml
      invoke  resource_route
       route    resources :products
      invoke  inherited_resources_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/controllers/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/helpers/products_helper_test.rb
      invoke    jbuilder
      create      app/views/products/index.json.jbuilder
      create      app/views/products/show.json.jbuilder
      invoke  assets
      invoke    coffee
      create      app/assets/javascripts/products.js.coffee
      invoke    scss
      create      app/assets/stylesheets/products.css.scss
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.css.scss

但是当我打开控制器 app/controllers/products_controller.rb 它是空的,为什么会这样??

but when i open the controller app/controllers/products_controller.rb it is empty, why so ??

还有一件事我也在使用 activeadmin,我知道它与它无关.

1 more thing i'm also using activeadmin, i know it has nothing to do with it.

推荐答案

我无法在基本的 Rails 安装中重现此问题:

I can't reproduce this on a basic Rails installation:

$ rails new empty && cd empty
$ rails g scaffold Post title desc:text
$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean

在此之后,app/controllers/products_controller.rb 拥有我期望的所有行:

After this, app/controllers/products_controller.rb has all the lines I'd expect it to have:

$ wc -l app/controllers/products_controller.rb
      74 app/controllers/products_controller.rb

也就是说,如果我将 ActiveAdmin 添加到 Gemfile:

That said, if I add ActiveAdmin to the Gemfile:

$ echo 'gem "activeadmin", github: "gregbell/active_admin"' >> Gemfile && bundle

并生成脚手架:

$ rails g scaffold product name:string information:text 'price:decimal{7,2}' stock:integer available:boolean

我的app/controllers/products_controller.rb 包含的代码少得多.它不是空的,但几乎是:

my app/controllers/products_controller.rb contains a lot less code. It's not empty, but almost:

class ProductsController < InheritedResources::Base
end

如果这也是您所看到的,那么您的问题是因为 ActiveAdmin 使用了继承的资源来完成一些繁重的工作.你最终得到了一个 InheritedResource 控制器.

If this is also what you're seeing, your problem comes from the fact that ActiveAdmin uses inherited_resources to do some of the heavy lifting. And you've ended up with am InheritedResource controller.

不过,控制器应该可以正常工作.

The controller should work perfectly fine, though.

这篇关于脚手架 Rails4 空控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆