Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- adding faker:
- add faker gem to Gemfile "gem 'faker'"
- ****everytime you change the Gemfile, you must bundle install**** ('bundle install' in terminal)
- add 'Faker' within the seeds.rb tab
- ie: email: Faker::Internet.free_email("#{first_name}, #{last_name}"),
- rake db:seed in terminal
- post verbs: post, patch, delete (change, but not display) (these are the ones that view's are redirected to show/index/etc)
- Flash Hash
- Step 1 (in application.html.erb)
- <% flash.each do |name, message| %>
- <%= message %>
- <% end %>
- Step 2 (in controller)
- flash[:success] = "Successfully Updated Recipe"
- Flash messages are only viewed ON THE NEXT HTML RENDER. If you refresh the page, the flash message will be gone. (used in create, update, and destroy)
- Change/Update Database Model without destroying it (MIGRATION)
- 1) create new rails migration app
- 2) go to db-migrate-jibberishfilename and check model is what you were expecting. Check input types (string, integer, etc)
- (once you make this page, you can edit it until you 'rake:db migrate' - once it is in the database you DO NOT edit this page, otherwise you could blow everything up)
- Edit Database after it has been migrated:
- in terminal: "rails g migration AddPriceToProducts" (this will make the file add_price_to_products.rb in the migrate folder)
- ^^ this will add a new migration file to the 'migrate' folder
- open the file and add to the method "change"
- example: add_column :products, :price, :integer
- ^^ name of table, name of attribute(column), name of data type
- rake db:migrate - this will add in the changes to the database
- (note: this will update schema.rb file) (reminder: never touch schema file, to make changes you need migration files)
- rake db:create - adds folders to empty file cabinet
- rake g migration - creates new file that describes folders
- rake db:migreate - translates ruby code into sequel and enters the database
- seeds.rb - static ruby file with all information - in order to run this static file into SQL we run -->
- 'rake db:seed' - this makes the ruby data into the structure of the file cabinet (SQL)
- **You must have structure of database before migrating**
- SHORTCUT FOR MIGRATING (IN TERMINAL)
- "rails g migration AddStockToProducts stock: integer"
- ^^ this will create a new migration file with a new column for Stock in table Products with data type Integer - review and then rake db:migrate
- "rails g migration RemoveStockFromProducts stock: integer"
- ^^ This will create a new migration file which will delete the Stock column from the Products table, with data type integer
- db:migrate has 3 possible outcomes: error, success, literally nothing
- schema.rb - report of current structure of database
- COLUMN TYPES
- string - limited to 255 characters
- text - unlimited characters
- integer - whole numbers
- float - not an available data type for postgres, instead they use:
- decimals - exact, instead of having .28 *100= 28.00000000000004
- boolean - use to store true/false values
- binary - used to stroe images, movies, and other files in their original, raw format - any media (heroku can't store binary files) (stick to URLs)
- :primary_key -
- date -
- time -
- DateTime -
- Timestamp -
Add Comment
Please, Sign In to add comment