jhyatt1017
9/29/2017 - 11:51 PM

Rails Generators

Rails Generators

#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