That One Time I Subbed at SMU’s Coding Bootcamp

Sub at Coding Bootcamp

I was asked to step in as an instructor for SMU Coding Bootcamp with Trilogy. Our regular instructor was out of town and the instructor for the other class was burnt out from teaching our class plus his class. They gave me a two week notice to do it so it wasn’t like I found out at the last minute so I did have time to prepare for it. It was very nerve racking leading up to it, I was very nervous – I look at a lot of material and looked up many things and tried to find the answers to questions I thought the students would ask about.

We were going to be talking about scope and reviewing some JQuery. I wasn’t hung up about the JQuery because I knew enough of it to be okay, I was more concerned about scope since it’s more conceptual. I went over the exercises and researched a lot. Since it was week 4 into the program, I knew many wanted to know how they would the concepts relate to the real world especially when it came to nested functions. After much research on figuring out when to use nested functions in the real world, I decided to slack the other instructor and ask him if he knew of any real world uses for nested functions. He immediately responded back with ‘JQuery’ and I immediately thought ‘Duh, that makes sense since we are nested a response after a user triggers some activity’. What’s really funny is after all that, no one even asked about it but I did mention it to them.

The class went pretty well – We got through it and I was able to get it done but I don’t feel very confident my experience trying to communicate scope to the students. I realized, I should probably stick to being a TA for now just because I didn’t know if that role was one that was for me but it was definitely a good experience/exposure to have. I did find out that when the regular  instructor is out for June that they will have a substitute instructor for the class. This makes me feel a lot better because I get intimidated with teaching the coding bootcamp since I don’t have industry experience as a developer. I work with kids and have side projects where I build websites and applications but I am not a developer at a company. It’s always intimidating and nerve racking since you’re in front of adults who want to ultimately become a developer at the end of the course and I feel like they look at me like ‘You’re just a grade school teacher, why are you here, you can’t really help us’. I definitely went into this with that feeling and went out feeling somewhat the same even though they did say I did a good job but I didn’t believe them lol. I did mention to the regular instructor the same thing how I thought it went decently but not as good as he would have done but he did say he’s sure I did fine.

We do record the classes for students to be able to watch over but I have no intention of reviewing my take because I know its going to be total cringe-worthy.

When it’s all said and done my advice is to just take risks – If someone asks you to do something that’s maybe out of your ordinary comfort zone then give it a try.

Coding Bootcamp Application Process and Getting Funding

First Steps are tough: 

The first step to getting into coding bootcamp is applying to one but this can also be the toughest part to complete. I encourage you to take the first leap into your future and step out of faith if coding is something that really enjoy and you want to make it your full time job.

Apply:

Access the website to which you are applying and find the application. Be honest when filling out the information and if your bootcamp has options to filling out a scholarship application while applying for the bootcamp, fill those out as well. Even if you don’t get the scholarship, you filled it out and tried. Remember you can’t win the game if you don’t show up to play.

Also note that if you are applying to multiple bootcamps that you should pay attention to deadlines and send in all applications at the same time if possible to increase your chances of hearing back around the same times.

Waiting:

Once you’ve sent out your application, it’s the waiting game but you should note that while you’re waiting you should still be working. You should be practicing coding as often as possible if not everyday after all this is your passion and you will have an interview for the coding bootcamps you have applied for.

Interview:

Awesome, you’ve heard back and they want to set up an interview! During this process show what you know. I was asked to code loops and functions on the screen using javascript (or any language your comfortable with). I thought I did terrible but the interviewer said I did well. One thing I didn’t realize I was doing at the time was talking out the problem and the solution.

Some tips:

  1. Keep communicating with the interviewer
  2. Be honest about what you don’t know – You can only do what you know!
  3. Interview in a place where it’s quiet and you won’t be bothered/distracted
  4. Have fun 🙂

Funding

There’s nothing better than to hear “Congrats you got accepted!!!” It’s then you realize this is really and that you need to get the money to go. There’s some ways you can go about this:

  1. Use savings (ex. 401K) – As long as you also have the funds to live off of
  2. Pay out of pocket – If you have the money sitting in the banks, by all means use it better yourself
  3. Go Fund Me page – Try this out and send it to friends and family to help support the cause
  4. Get a loan

Many people who want to attend a coding bootcamp are going to be in the fourth category and that’s okay. Remember that you are bettering yourself and following your passion so do what you have to do in order to succeed. Sometimes you have to use all the options above. I used the money for my 401K for living expenses and got a loan to pay for the schooling. I also received a scholarship to pay for some of the bootcamp.

Loans:

Here are some of the places I went to to get a loan:

  1. Climb: climbcredit.com
  2. Pave: hello.pave.com
  3. Upstart: upstart.com

Unfortunately, I was rejected by the above and told admissions that I would not be able to attend. Fortunately I did so because they pointed me to another source that did agree to loan me the funds to attend the bootcamp.

Earnest: earnest.com

I applied for a personal loan through Earnest. During the application process they ask you how getting the loan would help you achieve your goals. They’ll ask you the details about the coding bootcamp you are going to and also ask you what the remaining balance left to pay is – If you are unsure, it’s okay. If approved, they will work will the coding bootcamp to figure it out. Finally, they provide 1, 2 and 3 year options on paying back the loan – whichever is most comfortable for you.

  1. Please note that checking your rate through any of these sources does not affect your credit score.
  2. Also note that your coding bootcamp may have a referral link for any of the loan companies you are considering so make sure to go through their website first.
  3. Lastly, when requesting funds, I wanted to get enough for living expenses and once my loan was approved, they stated they could only give me the remaining balance of the cost of my coding bootcamp so keep that in mind while applying. If your coding bootcamp operates the same, make sure to have living expenses from savings or to take out a personal loan to cover your expenses.

Creating a Model in Rails

Creating a Model in Rails

  1. In the terminal where your project folder is located, create a new model.     

 a. I’m creating a Users table  with a first_name, last_name, username, password, street, city and state. Password:digest coupled with the bcrypt gem is used to securely store the users password and allows for easy password authentication when completing forms.
rails-g-model

b. Once the table is created, it’s time to rake db:migrate – This command will pull the model for use in your project.

rake-db-migrate

    1. Let’s say you made a mistake with your table and want to replace, update or remove information or the whole table. 

a. It’s pretty simple with rails to alter your table – after creating a new rails g migration NameOfColumnToAdjust, just go to the migration file that’s created in your migrate —> db folder, create a new method using ‘def methodName’ then choose a command you wish to utilize, add in the name of the field, the data type and what you want it changed it. Finally add ‘end’ to your method to close.

rails-g-migration-addnewcolumntousers

b. Back in your terminal run rake db:migrate to merge the changes to your table.

Creating a New Rails Project

As you probably already know, a few months ago, I completed a coding bootcamp where I learned a few coding languages. One of them being Ruby on Rails – It’s been awhile since I’ve created a Rails application so I decided to create a banking app where users can log in, make deposits and withdrawals, update their profile and possibly down the line make it so a user can apply for a loan. The purpose of starting this project is to use the skills I don’t want to lose – as the saying goes “Use it or lose it”…I don’t want to lose it.

The inspiration from the project comes from the hackathon I helped organize last month (firsthackdallas.com), many of the participants utilized Rails and I kept thinking to myself ‘It’s been awhile since I created anything in Rails’ so I decided to create this project.

I also have a full time job as a Business Systems Analyst (more details on this in a later post) so I’m working on this project in my down time, namely when I get home from work so it will be a slow moving project.

Finally, I have never fully used my blog as a teaching platform/a way to communicate to others what I learned so I wanted to at least start with creating a new rails application because when I started this project, I definitely had to go back and look up how to get the project up and running & thus thought this would be a great way to write out how to start it so that next time I can use it as a reference. Fortunately, the process is not that difficult if you already have rails installed on my computer.

**Please note: This tutorial assumes you have rails up and running on your computer.**

  1. Navigate to the folder in the terminal where you want the new project
  2. In the terminal, create a new rails project: rails new project_name
  3. Navigate to the newly created project from the terminal: cd project_name
    1. Start the server for the project: In a new tab in the terminal (ctrl + N) – type in rails s to boot up the server
    2. In your browser of choice, go to localhost:3000
      1. You should see the generic message from RailsGeneric Rails Message
  4. Open the project in your favorite text editor, I use Atom…Then, locate and open the views folder views folder
    1. From there right click and New Folder – Since I’m creating a banking application, I’m going to create a users folder to store all views related to users.
    2. Once the folder is created, right click on the folder name to select New File:
      1. Name the file any name of your choice. Since, I’m looking to have a fully RESTful application, I’m going to name my file index.html.erb
        1. In this file, create an h1 tag – <h1>My Index Page </h1> – Save the file. **Please not that if you try to view the page in your browser you would still see the generic Rails screen because this route is not defined in our routes folder. **
  5. Let’s define this route so we can view it: Open the routes.rb file (folder_name –> config –> routes.rb)
    1. Add a line in the file after line 6 in order to have a statement of code to make the new file you just created be the root of your website – That is, when you navigate to localhost:3000 this page shows up instead of the generic page from Rails that’s currently showing.
    2. Once you are on a new line, the format for how to create the root is: root:folder_name#file_name
      1. The folder_name will be what you named the folder from above – in my case it’s users
      2. The file_name will be the file that you created from above – in my case it’s index since I named the file index.html.erb
      3. In the end my statement looks like this: root:users#index
      4. Save the changes to this file.
  6. Back in your browser: Refresh the page and you should now see the h1 tag in your newly created file
  7. That’s it! You are now ready to work on your rails project.
  8. Next, we’ll create a model and controller for our project.

First Hack Dallas – Long Over Due Post

Before I start, let me begin by saying this post is WAAAAAYYYYYY overdue! We held First Hack Dallas on November 5th but I wrote this post a couple weeks ago – I had forgotten my password and then kept putting it off…Enough of the excuses, here’s the overview.

What a Saturday!

So, I’ve been holding out this whole time – Sorry! I’ve spent the last few months helping organizing a hackathon.

WTH? I know, kind of big deal but it was always difficult decision of how do I start talking about it, do I want to start talking about it and of course what if we failed completely.

I’ll give you a brief overview of how we started but will link to my co organizer’s blog here (http://www.acodingodyssey.com/2016/10/13/first-hack-dallas-a-hackathon-for-newbies/): We wanted a hackathon where new coders can work on a project that would be beneficial to the community. This environment would be way less intimidating then a regular hackathon where it could be intimidating to even want to register. At any rate, there were a total of seven organizers all graduates of Coding Dojo and we each held an integral part to making this hack fest happen.

The Day Of

This is it, the emails were sent out, of course some participants dropped out before it even started but there were others, eager to get started. I took over being the first face participants would see and checked everyone in. This was way more fun than I thought it would be – I was excited and you could tell that. I even got a chance to bring out my humorous side and utilize my armor of bad jokes. There were a few stragglers and some didn’t bother to show up but we ended up with a cool 44 participants that showed up.

Everything ran smoothly except for the delayed start time, one hour to be exact but we let the hacking continue for an extra hour to make up for the time.

Throughout the day we had mentors tell us how great the event was. I spoke to some of the participants and gained valuable feedback, overall everyone was happy they came out, had fun, learned something new and wanted to do it again. Man, what a relief to know we created something that benefited people. I saw collaboration over many different scopes of life – That’s what I like about coding, developers come from all different paths. It was really amazing to see everyone working together.

It was an exhausting day for all of us, especially us organizers but I want to Thank each of every person on our team for coming together to make this event as great as it was. We truly gave participants the experience that we promised – Non intimidating atmosphere to code.

The Winners

The winners were a duo who made an api and robot to communicate with the user. It was simple and got the job done. See the presentation for this project here:

https://www.facebook.com/oscar.cortazar.1/videos/10153860621626644/

Congrats to Minh and Quang for taking home the grand prize.

Minh, Quang, Shiraz (Community Manager of Coding Dojo Dallas) and Ryan (part-organizer)
Minh, Quang, Shiraz (Community Manager of Coding Dojo Dallas) and Ryan (part-organizer)

Minh and Quang, walked away with a $500 cash prize (split between each other), 2 – $2000 scholarships to attend Coding Dojo, 2 – Coding Dojo mugs and 2 – Coding Dojo sweatshirts!

The Beneficiaries

First Hack Dallas’ first hackathon benefited RedRibbon.us, which is an organization that provides a centralized support system for those in the Dallas community impacted by HIV/AIDS.

Find RedRibbon Here: 

http://www.redribbon.us/

https://twitter.com/RedRibbonUS

https://www.facebook.com/RedRibbon.us/?ref=aymt_homepage_panel 

Something to Learn

Maybe something to take to our next hackathon is to have the list of languages each developer is good at under each participant name and definitely find an easier way to raffle (we used an algorithm to shuffle the names in our database but at first it only pulled out email addresses and sometimes we had technical difficulties).

Farewell to Next Time

A special thanks to all the participants – I know sometimes it’s not easy to go to an event where you may not know anybody and have to learn how to work together. We had a couple people waiver away in the afternoon but we definitely appreciate everybody that showed up, coded their heart at and never gave up. It’s difficult to want to keep going if team members leave or you’re down to your last couple hours and everything is breaking but remember you have to keep going!

I’m sure we’ll do this again and look forward to help organize again! I had a blast, even though I dozed off in the corner a few times throughout the day. I definitely felt proud of all the people who made this possible. Thanks to all of our sponsors:

Fort Work – http://www.dallasfortwork.com/ 

Minecraft U – http://minecraftu.org/

Women Who Code Dallas – https://www.womenwhocode.com/dfw 

High Brew Coffee – http://www.highbrewcoffee.com/ 

The DEC – http://thedec.co/ 

Boost Stream – http://stefanieorozco.com/ 

Coding Dojo – http://www.codingdojo.com/ 

Odyssey Information Services – http://odysseyis.com/ 

Modern Message – https://modernmsg.com/ 

Dialogs – https://www.dialogs.com/ 

Draw Attention – http://www.drawattention.co/

Major Thanks to the mentors who showed up and answered questions from our participants.

The Organizers: 

(L-R)Farhan, Oscar, Ryan, Terry, Cody, Chris and Me (Tiffany)
(L-R)Farhan, Oscar, Ryan, Terry, Cody, Chris and Me (Tiffany)

Anything is Possible

I want anyone to know who’s reading this that anything is possible. Don’t give up, keep going. There were tough times while we organized this event and a point we didn’t think it would happen but we pulled together our resources and produced an event that turned out better than we thought.

Until next time,

Keep knocking down doors and opening new opportunities.

Where Have I Been?

It’s been a few months since I posted about graduation. What’s been going on since then you may ask?

I’ve had some email and phone screens and a few interviews but I have yet to land my first developer position that I’ve been looking for. Everyone seems to be looking for Mid-Senior level developers that know what their doing. Most do not want to train an eager developer such as myself. At first, I was pretty upset about it but now it’s pretty much my reality that I don’t have a job so I don’t spend my time being upset, I just keep applying for relevant positions and attending meetups hoping for a day that I can land my first dev position.

I’m not going to say that it’s been an easy journey so far but I can’t complain with how things are going. Things could be worse so I’ll take what I can get. I know what you’re probably wondering…Do you regret leaving your job and attending coding bootcamp?

The short answer is no. The long answer is that I definitely feel the experience of attending Coding Dojo has made me a more confident developer. I’m not afraid to apply the skills I’ve learned to the real world environment. I know that the experience at the Dojo can set me up to working in many different industries using many different technologies based on the skills that I’ve learned while I was there.

So, What have I been doing to keep up my coding skills?

Excellent question! I have a knack for volunteering so I’ve been doing just that. I went to volunteermatch.org found opportunities that I feel I could contribute to and have applied, talked to the owners of the non profits and am now contributing to web applications.

The first one I applied for was in early September – I am volunteering virtually. They are currently using the LAMP stack to create a web application to benefit teens across the world. I have joined the Front End team for this project so many of my efforts are going to make sure the site looks like great using HTML, CSS and Bootstrap.

The second effort I am contributing to is a Disaster Relief web application for first responders in disaster struck areas. This group is using Java and Spring on the Back End – two that I know nothing about but it looks pretty cool. I am also a part of the Front End Team using HTML, Materialize CSS, Angular 2 and Typescript to make the site look and function correctly. It’s been pretty interesting working with Angular 2 and Typescript – I’ve only worked with Angular 1 up until then and there are many differences.

For both organizations, I am keeping the integrity of the web applications we are working on so the above details may be a bit vague. I plan to blog about some challenges that I’ve come across and things that have gone well – Don’t hold me to it though.

As you can see, I’m not necessarily working at an actual paying gig in tech but I am utilizing my skills to help out real non profits across America (both of the two I’m helping out with are located on the East cost with team members spread across the world).

Overall, I’m excited about my journey and where it may lead.

It’s Graduation Day!

Well, I made it! 14 weeks of learning 3 full stacks.

It’s graduation day at the Dojo today. Today started like any normal day. I got to the Dojo at 8am, started looking at job descriptions and tried to my reset my Indeed password. I’ve had an account with them before – I figured that out yesterday when I accessed it on my phone and was surprisingly able to save jobs I was interested in. Apparently their system was having issues because it gave me an error every time I tried to change my password…I ended up using my phone to go through the process of changing my password, which surprisingly didn’t have any issues. I applied for a job I saved and looked through some others.

Afterwards, I looked at the post bootcamp section of the platform – it became available to the graduating cohort today. The first thing was algorithms so I got out pencil, paper and my console and got to work – printing an array of values, printing the reverse of the array of values, finding the average/max/min of the array of values. The most complicated one for me? Inserting a value at an index. Why? Because if there’s a value there you have to make sure you don’t lose it. I struggled with this one for awhile before looking at the video explaining the process –  Add a zero at the end of the array (makes sense because you know you’re going to only add one value), starting at the end of the array – copy the values to the end of the array, then add the value at the index…Makes perfectly good sense now. I was trying all other things such as adding an if check to determine if the index of the current array matched the index of the value given by the user, then set the current value to a temp variable, replace the current value with the value given by user, then push the temp variable (which holds the original value) problem with this is that you can only push to the end of the array which may not always be the case. Not only that, but it just doesn’t work in the console – it results in an error and no output is given.

After looking through the first section of algorithms, which amounted to 18 algorithms, I switched gears and took a look at the job search section. The platform provided me great tips on the search booleans recruiters use to find applicants, what information should be on a resume and how to go about looking for the jobs you want to find. The whole video was an 1 1/2 hours long but after 40 mins it was practically time to start our ‘graduation’ so I decided to finish later on.

The graduation

I’ve been to enough graduations to know the graduation song and you better believe our instructor had it playing at the start of the ‘ceremony’ in a jokingly manner. I put ceremony in quotes because it was just the graduates and some people from other cohorts that stuck around. A few graduates presented projects – some from the MEAN stack others in Rails. The lead instructor said a few kind words and we had pizza and brownies! Afterwards we took these great group photos:

Slack for iOS Upload

And a goofy one for the road:Slack for iOS Upload-1

There is one grad not pictured here – he headed back to Seattle the morning of. The guy in the back facing his computer in the yellow was retaking his belt exam in hopes a perfect score. The guy in the red is not in the graduating cohort but his cohort is pretty nonexistent – There’s only four of them total so we adopted him into our group – He fits in perfectly.

In Conclusion:

All in all, I’d say we had a really good group and I am fully glad I decided to pursue this journey. The journey is not fully over because the next step is to get job ready! Next Tuesday, most of us will return and begin the next chapter – finishing projects, working on algorithms and figuring out how to start a career in this industry. I’m excited and pretty nervous! I’ve no doubt that we’re all capable of finding a fulfilling career of our dreams.

Thursday – June 30th – One More Day Left of Bootcamp

Twas the last day of June and not many were at the Dojo

Today started off pretty blah. I was the first in my cohort to arrive at the Dojo today and by about 9am there were only four of us total here. Another person trickled in in the afternoon.

At any rate, I had a productive day today! I spent some of my morning writing a blog post that was long over due. Once that was out of the way, I started looking at some Rails associations from the platform. Afterwards, I went back to the LAMP stack to see if there were any projects to I could recreate in Rails. I noticed one – involving Products (showing and removing products)…that sparked an idea to add login and registration to it and instead of any product…create books.

At 3:30pm I had completed the login/registration/logout, show page(user dashboard) that displays a list of books that are added by users —- The user who created a book can edit (updating the title, description, quantity or price) or remove the book. There also another table that can display the books that the user purchased. And finally a user can cancel an order by deleting the row in the associated table.

Here’s some of my work in the console:Screen Shot 2016-06-30 at 3.35.38 PM

Snippets of my Books controller:Books Controller

User Dashboard Controller: User Dashboard Controller

Routes file:
Routes File

I have to say, I’m pretty excited about what I created in about 5 1/2 hours (with a couple breaks in between). It’s rather exciting because three months ago I wouldn’t have been able to get that far – Now, because I have a better understanding of queries, making information appear on view pages and getting the data submitted by the user; I am able to press forward. I’m excited to put these skills to good use.

The Last Days of Bootcamp

The bootcamp is just about over and I haven’t blogged in a bit.

Let’s start with a little bit about last week.

About Last Week:

Last week was mainly about planning to take the belt exam on Friday. I wrapped up a couple of assignments at the beginning of the week and by the middle of the week I was ready to work on the belt exam prep test. If I never mentioned it before – the belt exam is a test taken at the end of three weeks of every stack to test our knowledge of the stack. During the test, which are given 4 1/2 hours to complete, we get a wireframe of what we need to do and instructions of what our final product should expect to have. There’s always a login/registration page, which after a successful attempt should log a user into their page which includes things like where you can add an item such as an event, a show page – which shows more about a particular event and sometimes a table of all the events added by every user.

We took our exam Friday afternoon and I have to admit that I felt I did better at my first attempt than I have on past exams. I managed to finish deploying within the next our the test is over and was on my out the door by 7pm.

This week…so far:

The week started of with a small group in my cohort. It was our last week, which is time we spend working on a project, catching up on past material we may have didn’t grasp or couldn’t get to or retaking our belt exam if we felt the need. On Monday, there were about 5 people here from my cohort. I worked on updating my personal website and going over some stuff on my exam from Friday and making the finish product look nicer.

On Tuesday there were a couple more people that trickled in and I had a tough time concentrating because I’m very exciting for the end of the program. I received my belt exam results back and found out that I received a red belt – which in my case was 1.3 points away from a black belt. With that news, I decided I’d head home since I knew I wasn’t getting any work done. At first, I told my instructor I wasn’t going to retake but after my 30 minute train ride home, I decided to regroup and to retake on Saturday.

On Wednesday, I didn’t go in to the dojo – I wanted to stay at home to concentrate in silence so I could go over what went wrong on my exam. One of my main issues is that I had extra information in my table that didn’t need to be there – it was as if the query I had been used was looping multiple times and I found out later that that was the case. To fix this issue, I wracked my brain for hours before taking a break to run some errands since I was at home. When I returned I felt revived and went straight to my computer and got to work. Turns out I needed to to do a join and select the columns I needed from each table so I could just loop through them and get the data I needed one time instead of multiple times. Here’s the query I used:

@lend = Lender.joins(:histories).select(“lenders.first_name, lenders.last_name, lenders.email”).select(“histories.amount, histories.borrower_id, histories.lender_id”)

This query joins the Lender and History tables and selects the lender’s first and last name and email. It also selects the histories amount and id’s of both the borrower and lender. Once this was set into place, it was easy to loop through this to get the information for my table as below:

  <% @lend.each do |help| %>

      <% if help.lender_id == session[:user_id] %>

       <tr>

        <td><%= help.first_name %> <%= help.last_name %></td>

        <td><%= help.purpose %></td>

        <td><%= help.description %></td>

        <td><%= help.needed %></td>

        <td><%= help.raised %></td>

         <td><%= help.amount %></td>

      </tr>

    <% end %>

  <% end %>

I felt pretty accomplished after this – It may seem like a small feat to anyone else but it took a long process to come up with the query to use. I used my rails console to try out different queries in order to figure out which one would give me the data I needed.

Making Tests Work with RSpec and Capybara in Rails

This past weekend I worked on the next section which was Rails II – basically we were to build the project and utilize testing to make sure it would work. There were different levels one could do to complete this assignment: 1. Do the assignment without testing 2. Make the assignment work with the testing they provided on the platform or 3. Write your own tests in addition to the ones that were provided. This assignment was like a series, in which we add onto the project with each assignment we complete. We were given a wireframe and the tests and were set loose.

The project is to login or register a user, upon logon this page will redirect to the users Secrets page where a user can create their own secret, show the secrets they’ve liked or delete secrets they’ve created. There was a Secrets page which displayed all the secrets, allowed only the user logged in to like/unlike or delete the secrets they’ve created (much like the users’ show page). Along the way, we also implemented User Authentication (which is how we allowed only the logged in user to navigate through the app)

It turns out it’s as easy as putting a method at the top of our UsersController:

before_action :require_login, except: [:new, :create]

The above code states that before you do anything, go to the require_login method which verifies if the user is indeed the user that’s logged in via the session[:user_id] variable. The exception in this case is the new and create methods — A user should be able to access the page to create a new session by logging in or registering as a new user.

In the Secrets Controller, we added this code:

before_action :require_login, only: [:index, :create, :destroy]

Which states that before you go to any method, make sure that the user trying to access the page is indeed the user that’s logged in (as above) and if not, redirect that person back to the page where they can create an account or login. In the only:  tag, we allow only the logged in user access the index, create and destroy methods. We created tests for these methods.

Next up is the User Authorization. This is the code that’s put at the top of our UsersController:

before_action :require_correct_user, only: [:show, :edit, :update, :destroy]

The require_correct_user is used to define if the user is the one logged in and if not, redirects that user to their own page so they aren’t able to view everyone else’s pages…here’s the method defined in the application_controller:

  def require_correct_user

    user = User.find(params[:id])

    redirect_to “/users/#{current_user.id}” if current_user != user

  end

The last part of this section was to create our own tests for the User Authorization and User Authentication. I’ll leave you with some snippets of my tests:

likes_controller_spec

likes_controller_spec_2