ruby-on-rails – 在Rails中更改scaffold-controller-generator-
当我使用Rails脚手架生成器创建我的Rails文件时,它会创建一个控制器文件.例如
铁轨生成脚手架土豆 产生: 应用程序/控制器/ potatos_controller.rb 对于我的项目,我希望这个文件更具体一些.例如.我想更改此自动生成的操作: def create @potato = Potato.new(potato_params) respond_to do |format| if @potato.save format.html { redirect_to @potato,notice: 'Potato was successfully created.' } format.json { render :show,status: :created,location: @potato } else format.html { render :new } format.json { render json: @potato.errors,status: :unprocessable_entity } end end end 使用I18n翻译而不是硬编码’马铃薯已成功创建’.另外我想改变一些缩进,因为rubocop总是抱怨它. 我找到了脚手架 – 发电机的模板,现在想要进行更改.为此,我在我的项目中创建了一个文件: redirect_to @<%= singular_table_name %>,notice: <%= "'#{human_name} was successfully created.'" %> 至 redirect_to @<%= singular_table_name %>,notice: <%= "'#{human_name} THIS IS A TEST.'" %> 但不幸的是,这些变化无效.脚手架生成器仍然使用自己的模板.那么我在这里做错了什么?我错过了一步吗? 更新: rails generate scaffold potato Running via Spring preloader in process 31479 invoke active_record ... invoke scaffold_controller create app/controllers/potatos_controller.rb ... 铁路的屏幕截图: 解决方法
Rails 4显示了正在使用的模板
rails generate scaffold potato ... invoke scaffold_controller 您应该在项目中托管修改后的模板,即 请注意,Responders gem可能会更改用于的生成器LIB /模板/导轨/ responders_controller / controller.rb. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- C#各种配置文件使用,操作方法总结
- ruby-on-rails – 如何删除rails 3.1中的`references`列?
- Using SQLCipher to encrypt sqlite db (for iOS)
- 11.20 小程序开发总结 (1)
- 学习笔记 - React Native
- postgresql – 截断Postgres数据库中的所有表
- 打开VB出现窗体名称冲突解决方法
- postgresql – node-postgres:设置最大连接池大小
- 【第28篇】通过Gson和FastJson格式化Json数据
- oracle 10g 出现Fatal NI connect error 12170错误