Archive for the ‘Rails’ Category

Rails: Add Authentication to Your Ruby on Rails Website in 4 Easy Steps

Step 1
In the terminal:

gem install Devise
bundle install
rails generate devise:install
rails generate devise user
rake db:migrate

Step 2
In seeds.rb:

user = User.create(email: 'name@name.com', password: 'password1', password_confirmation: 'password1')

Step 3
In the terminal:

rake db:seed

A route will be automatically created by the devise gem

Step 4

In _topnav.html.erb:
Add an if statement to check if the user is logged in:

if user_signed_in?

rubylang

Rails: Migration Files

When you generate a model in Ruby on Rails

rails generate model somename

A migration table is also generated.

The Migration is a table that describes a database and the information it holds in columns.
rubylang

Rails: Add data from seeds to db in 1 Line

rake db:seed