- Resources: Rendering & Redirecting
- Render tells Rails which view or asset to show a user, without losing access to any variables defined in the controller action.
- The redirect_to method tells your browser to send a request to another URL. Since the request is completely different, the view to which you redirect will NOT have access to any variables defined in the controller.
- Rails Authentication Video example (timecode 4:40)
has_secure_password
gives us the .authenticate method in our Controller, what encrypts our password when we pass it in our password column, in table calledpassword_digest
- How does
password_digest
work? Original password is NEVER saved, bcrypt encrypted the password for us before saving it in the database - Explain
bcrypt
:bcrypt
salt and hash password, encrypt our password
- Ruby Guides: When to use Scope, Scope VS Class Method
- Active Record Scope Methods (Seth @ Flatiron) 34mins
- What is scope method? Class level methods that limit your return to be a scope return.
- Scopes are custom queries that you define inside your Rails models with the scope method.
- When working on scope method, look at schema, the attributes are the ones we have opportunity to work from
- API DOC: ActiveRecord::Scoping::Named::ClassMethods
- Question: Difference between scope method and class method
- (Medium) How is a scope different from a class method?
- Chaining - it will not return
nil
but rather an empty array - Readability - Scopes can be written in just one line, great way to keep your model dry
- Chaining - it will not return
- Don't call database from View
- Think MVC
- Walk-through Google OmniAuth in browser, in code
- Refactored
google_login
method
- Refactored
- Walk-through "Sign in" in browser, in code
- Explain
@user.authenticate
, why wouldn't@user.password_digest
work? Refer to Password notes above. - Show how the join table happens, the many-to-many relationship in browser and in code
- Refactored
current_user
helper method, read more on=||
or equals ruby (stackoverflow), don't call database too often, only call it when you need it, now your app is small, but when you have a lot of users in database, it might slows you down if you keep calling database - Show Scope method in browser and in the code
- Explain the difference between using Scope Method or using Class Method with the scope, there is no real big difference, but using scope has its advantage in terms of organization, easier to spot it when you have a lot of Class Methods and Scope Methods in your app, Scope Method would return empty
activerecord:relation
- Explain the difference between using Scope Method or using Class Method with the scope, there is no real big difference, but using scope has its advantage in terms of organization, easier to spot it when you have a lot of Class Methods and Scope Methods in your app, Scope Method would return empty
- Nested routes and live coding (do scope, where)
- Live coding question: "find username using scope"
- Live coding question: "find the team with the most users"
- Use join in scope, joining two tables first, (stackoverflow)
Steps I took:
- Ask more clarifying questions if needed (it helps make you less nervous)
- pull out your notes to pseudo code first (write down what the instructions were)
- Talk your thoughts out loud throughout the whole process
- You can google!! (only refer to ruby guides, api docs etc, no stackoverflow)
- Relax, think of the instructor as your pair programming buddy
- "What can I learn from this review? What can I learn from this live coding session?"