Applications open until spots fill up - Apply now.

Bonus 1 - Basic Authentication

Bonus 1 - Basic Authentication

August 18, 2015

Project: Build a Ruby on Rails blog with cats (and unicorns)

If you were to publish your blog online, anyone would be able to add articles. Rails provides a very simple HTTP authentication system that will work nicely in this situation.

What is HTTP?
When you enter a URL in your browser, this sends an HTTP command to the Web server directing it to fetch and transmit the requested Web page. HTTP stands for HyperText Transfer Protocol.

Open the articles_controller.rb again and add the following line of code at the top of the file:

class ArticlesController < ApplicationController

  http_basic_authenticate_with name: "alena", password: "secret", except: [:index, :show]

  def index

. . . shortened for brevity . . .

You can of course change your name and password!

When you reload the Listing Articles page now and click on the New Article button, you should get a popup similar to this:

Basic authentication

And that's already it. How easy was that?!


If you have feedback on this tutorial or find any mistakes, please open issues on the GitHub Repository.

Join Make School

Prepare for your career as a founder or software developer

Apply Now

Talk to Us

If you have any questions, please send us an email

Email Us