ruby Rails生成器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Rails生成器相关的知识,希望对你有一定的参考价值。

#Rails g (generator) command
#--no-test-framework is a flag that tells the generator not to create any tests for the newly-generated models, controllers, etc
rails g <name of generator> <options> 


#MIGRATION GENERATOR
#Let's start using database migrations in our case study application and update the posts table. To add a new column called published_status
rails g migration add_published_status_to_posts published_status:string 
#get rid of that column name with another migration:
rails g migration remove_published_status_from_posts published_status:string 
####
rails g migration add_post_status_to_posts post_status:boolean 
#Changes from boolean to string
rails g migration change_column :posts, :post_status, :string 


#MODEL GENERATOR
#add a new model to the app called Author with columns name, genre and bio
rails g model Author name:string genre:string bio:text --no-test-framework
#create author for Author class
Author.create!(name: "Stephen King", genre: "Horror", bio: "Bio details go here")


#CONTROLLER GENERATOR
#Create an admin controller that will manage the data flow and view rendering for our admin dashboard pages:
rails g controller admin dashboard stats financials settings 


#RESOURCE GENERATOR ... creates a full CRUD routes
#manually create your views
rails g resource Account name:string payment_status:string 


#SCAFFOLD GENERATOR
#a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.
rails g scaffold Article title:string body:text 

以上是关于ruby Rails生成器的主要内容,如果未能解决你的问题,请参考以下文章

ruby Rails应用程序配置生成器

ruby rails生成随机字符串

ruby Rails应用程序生成器调整了我的共同需求

ruby rails3 prawn生成pdf

Ruby on Rails 有没有好的管理生成器?

Ruby on Rails 生成模型