一.建立rails 4 项目
rails -v # => 4.1.7 rails new customgenerator --skip-bundle # edit the gem source in Gemfile cd customgenerator bundle install rails s # visit http://127.0.0.1:3000/
二.添加脚手架配置
# in application.rb config.generators do |g| g.orm :active_record g.template_engine :erb # g.test_framework :test_unit, fixture: false g.test_framework nil g.stylesheets false g.javascripts false g.jbuilder false g.helper false end
根据需求自己配置,我的这样就干净多了.
然后下载rails 4.1.7,解压.
在lib文件夹下建立templates/erb/scaffold文件夹
# https://github.com/rails/rails/tree/master/railties/lib/rails/generators/erb/scaffold/templates # copy the five *.html.erb file to lib/templates/erb/scaffold/ # note: 不要后面的templates
三.使用
rails g scaffold User name:string pass:string salt:string
# the result invoke active_record create db/migrate/20141104024358_create_users.rb create app/models/user.rb invoke resource_route route resources :users invoke scaffold_controller create app/controllers/users_controller.rb invoke erb create app/views/users create app/views/users/index.html.erb create app/views/users/edit.html.erb create app/views/users/show.html.erb create app/views/users/new.html.erb create app/views/users/_form.html.erb invoke assets invoke coffee invoke scss
四.按照你的需要修改者五个文件
rails g scaffold Customuser name:string pass:string salt:string # the result invoke active_record create db/migrate/20141104024557_create_customusers.rb create app/models/customuser.rb invoke resource_route route resources :customusers invoke scaffold_controller create app/controllers/customusers_controller.rb invoke erb create app/views/customusers create app/views/customusers/index.html.erb create app/views/customusers/edit.html.erb create app/views/customusers/show.html.erb create app/views/customusers/new.html.erb create app/views/customusers/_form.html.erb invoke assets invoke coffee invoke scss # 我修改了 index.html.erb <h1>这是我自定义的模板</h1> <h1>这是我自定义的模板</h1> <table> <thead> <tr> <th>Name</th> <th>Pass</th> <th>Salt</th> <th colspan="3"></th> </tr> </thead> <tbody> <% @customusers.each do |customuser| %> <tr> <td><%= customuser.name %></td> <td><%= customuser.pass %></td> <td><%= customuser.salt %></td> <td><%= link_to 'Show', customuser %></td> <td><%= link_to 'Edit', edit_customuser_path(customuser) %></td> <td><%= link_to 'Destroy', customuser, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr> <% end %> </tbody> </table> <br> <%= link_to 'New Customuser', new_customuser_path %>
成功!!!
项目源代码: https://github.com/FlowerWrong/customgenerator
相关推荐
自定义配置使Rails.configuration点易于用作中央配置存储,即使对于Rails中未包含的东西也是如此。 # config/environments/production.rbBCX :: Application . configure do config . x . resque . jobs_inline = ...
支持rails2.0以上版本的配置说明,文档从我自己的博客中整理出来,不愿意用资源分的朋友可以去我的博客看: http://wudihamagong.spaces.live.com/ 或者 http://blog.csdn.net/abcdefg0 ^_^
initrailsix:为Rails 6自定义初始模板拉伸
Now in version 4, Rails is mature and powerful, and to use it effectively you need more than a few Google searches. You'll find no substitute for the guru's-eye-view of design, testing, deployment, ...
Ruby on Rails helps you produce high-quality, beautiful-looking web applications quickly. You concentrate on creating the application, and Rails takes care of the details., Tens of thousands of ...
Beginning Rails 4
Rails 4 Test Prescriptions.pdf
ruby rails radrails 环境 配置 图片加文字教你如何配置开发环境
Rails test described by RSpec
利用rails脚手架制作的简单网站.参考书本:web开发敏捷之道
Rails 的 React 脚手架应用程序 演示: : 许可证:麻省理工学院
Rails 4 in Action, Second Edition.pdf
rails 配置文档 ror ruby on rails
Windows7_Cygwin_Git_RVM_Ruby1.9.3_Rails3_MongoD B_Nginx_Unicorn_Rspec_Guard_Spork(2-Ruby on Rails3 安装配置
唔,1分应该还是有人下的吧,共同学习进步,Ruby on Rails is an open source web framework.... "Rails 4 in Action" is a fully-revised second edition of "Rails 3 in Action." This hands-on, compreh...
一本Rails 4开发进阶教程,适合有一定开发经验的Ruby on Rails开发人员阅读
学习ruby!
[Pragmatic Bookshelf] Crafting Rails 4 Applications Expert Practices for Everyday Rails Development (E-Book) ☆ 图书概要:☆ Get ready to see Rails as you've never seen it before. Learn how to ...
使用脚手架发电机 识别由脚手架生成器生成的组件和代码 描述与脚手架相关的代码(表单部分除外) 使用资源路由助手来生成RESTful路由 介绍 在我们回顾了Rails中每个流行的生成器。 我故意遗漏了一个:Rails ...