脚手架 Rails4 空控制器

编程入门 行业动态 更新时间:2024-10-22 21:30:10
本文介绍了脚手架 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 空控制器

本文发布于:2023-11-17 00:03:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608062.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚手架   控制器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!