Skip to content

Instantly share code, notes, and snippets.

@mathildathompson
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save mathildathompson/9613157 to your computer and use it in GitHub Desktop.

Select an option

Save mathildathompson/9613157 to your computer and use it in GitHub Desktop.
rails new projectname -d postgresql #1) creates a new poject using postgres by default;
#2) Database.yml file, change the username and delete production and test databases;
rake db:create #3) Create the database
rails is for high level stuff and rake is for tasks within your rails app;
#The column name in the database is the attribute in the model;
#Have 4 tabs running: bash, rails server, rails console, psql
\c to connect to database in psql;
- There will be a database for each of the test, datbase and
- REMEMBER THE APP CANNOT HAVE THE SAME NAME AS A MODEL;
- rake db:drop #Removes the database;
- rake -T #Shows all the tasks available in rake;
gem list | grep annotate
Annoate gem looks at model and database and tells you info about the model from the database;
annotate #Inside of the project
gem 'protected-attributes' #bundle;
class Planet
attr_accessible :name, :image, :orbit, :diameter, :mass, :moons #allowing us to mass assign (assigning things on mass) these attributes;
end
reload! #To reload the console (when you are inside the console)
Planet.destory_all #Destroy all the plantes in the database;
rake db:seed #Seed the database with data from the seed file;
Planet.destroy_all #Put this at the top of the seeds file to clear the database before I input data;
rails g migration create_planets #Create a migration file with a magic numbers with the exact time I generated the migration;
def change #The change the migration makes for us;
create_table :planets do |t|
up #Added the table
down #Removed the table
change #Lets us go backwards or forwards #Dont use this, use change instead;
rake db:migrate #created the table in the database;
rake db:rollback #Undo the last migration
rake db:migrate
rails g migration AddBreathableToPlanets breathable:boolean
render :text => 'testing test test test'
raise params.inspect
In the form you need name="planet[name]" etc.....
Planet.create( params[:planet] ) #Create a brand new planet
planet.update_attributes(params[:planet])
Planet.order(:orbit) #orders the plants by orbit;
render 'christmasplanets' #christmasplanets.html
Larry Wall
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment