Skip to content

Instantly share code, notes, and snippets.

@miclovich
Created February 21, 2015 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miclovich/cd6b3c543111f8162ffc to your computer and use it in GitHub Desktop.
Save miclovich/cd6b3c543111f8162ffc to your computer and use it in GitHub Desktop.
Rails workflow
VISION for an MVP (minimum viable product) // User story
==========================================
Create a competition [Iteration I]
--------------------
- football games
- picking winners
e.g Duke vs Carolina
Submissions (Bet)
- name, email, (user) who they think the winner is, answers to questions
User Registrations (ruby gem: Devise// learn how to build custom authentication)
- name
- email
- password
- tel-number
- address
-- etc.
is_admin??
Rights:
- create competitions
- ban users, etc.
Scores (through ESPN API, etc.)
------
- team1_score
- team2_score
Game
----
- team1's name
- team2's name
- relate to a bigger database tables ->
[Iteration II]
Team
----
- position
- player stats.. etc.
=============================
Schools of thought [Organize your thoughts]
2) x 1) Designing model (what we store or want to store - database)
1) x 2) UI (user interface)
a-v1) Photoshop mockups, napkins, paper, moleskin... sketches
a) controllers (ruby classes/methods)
b) views (embedded ruby and HTML/CSS/js/images/sounds, etc.)
3) Tests (usually done first!)
Handy commands
--------------
(once)
rails new app_name
repetitive...
Model
-*-*-*-*-*-
score: lkjxlljsdf? (makes no sence)
score: 34 (makes sense)
rails generate model Name attribute1:data_type attribute2:data_type
--------------------
| score | team |
--------------------
| 2 | arsenal |
| 2 | chelsea |
--------------------
Read up: Relationships!!!
e.g.
rails generate model Game score:integer team:string
Run the migrations (create tables in the database)
rake db:migrate
Tools for playing with ORM (its how we interact with a database)
===========================
rails console
e.g.
[option 1]
t = Game.create({score: 5, team: "chelsea"})
in ruby (optional)
t = Game.create score: 5, team: "chelsea"
(no need to save here, create does everything)
[option 2]
g = Game.new
g.score = 3
g.team = 'arsenal'
g.save
or
g = Game.new score: 5, team: "chelsea"
g.save
Controller
-*-*-*-*-*-
rails generate controller name_of_controller
e.g.
[option 1]
rails generate controller games
[option 2]
--> CRUD; create, read, update, delete
7 actions/methods
- new, index, show, destroy, update, edit, create
[create, destroy, update ] -> have no templates
rails g controller games index new show edit
-> create a folder games (inside app/views)
-> create a bunch of HTML templates (index, new, show, edit)
Workflow
-> new page
-> fill it out
-> click submit
-> get shown the page (new stuff)
-> edit, delete,
[] -> edit
-> update
-> show
[] -> delete
-> index (list of other stuff)
-> or home page, etc.
Running your app
---------------
rails server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment