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 . . .
end

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?!

Feedback

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

Summer academy

An iOS Development Summer Course

Design, code and launch your own app. Locations in San Francisco and Asia

Find your location

Product College

A computer science college

Graduate into a successful career as a founder or software engineer.

Learn more

Cookies on Make School's website

We have placed cookies on your device to ensure that we give you the best experience on our website.

This site uses cookies to deliver our services. By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Your use of Make School’s Products and Services is subject to these policies and terms.

Please note that Make School no longer supports Internet Explorer

We recommend upgrading to a modern web browser. Learn more