/ Published in: Rails
Basic Rails commands for newbies
Expand |
Embed | Plain Text
#################################### #Models #################################### #Create a Model $ ruby script/generate model ClassName attribute_name:attribute_type attribute_name:attribute_type #################################### #Controllers #################################### #Create a Controller $ ruby script/generate controller ClassName action1 action2 #Remove a Controller $ ruby script/destroy controller ClassName action1 action2 #################################### #Server #################################### #Start an application $ script/server #################################### #Migrations #################################### #Migrate does these 3 things #1. Checks the database for the unique number of the migration is most recent #2. It steps through the migrations that have not yet been applied, one at a time. #3. The Self.up method is executed for each migration $ rake db:migrate #Rollback a Migration $ rake db:migrate VERSION=n #Retrieving Records by ID, not recommended but at times helpful ModelName = (Most likely TableName) IRB>> ModelName.find(#id) IRB>> ModelName.find(:all) #Retrive the Last Record IRB>> ModelName.find(:all).last (Resource Intensive) IRB>> ModelName.find(:first, :order => 'id DESC') (Resource Efficient)
You need to login to post a comment.
