Setting up Devise gem for my first project

As you have read correctly, i started my first own web app 2 days ago. I’m still at the beginning , I created a navigation bar with links. I also made a form where users can post something.

I’m at the point where I start to make a forum section and all is working well so far. People can Create,Read,Update and Delete posts. I figured out some stuff I didnt quite knew at first like, linking to root_path. I know now that I have to look for the routing with:

> rake routes

It gives me a whole bunch of routes that rails made for all controllers with all the HTTP verbs and controller actions. So for example if I want to link to my post index page, I look where it says: posts#index. Then i look over to the get request and the prefix to see how I need to name my path, what would be: posts_path.

 

The next plans for the app are: payment system where users can pay each other and Authentification .

To begin with Authentification i need to setup Devise.

 

 

Devise

 

adding devise to our gemfile:

gem ‘devise’, ‘~> 4.2’

 

then:

rails generate devise:install

 

go to sublime and edit developement.rb file copy and paste:

config.action_mailer.default_url_options = { host: ‘localhost’, port: 3000 }

 

adding flash messages to application.html.erb:

<p class=”notice”><%= notice %></p>
<p class=”alert”><%= alert %></p>

 

by generating a User model with:

rails g devise user

 

Devise generated a whole bunch of code for the user model for example:

class DeviseCreateUsers < ActiveRecord::Migration[5.0]
 def change  
   create_table :users do |t|  #loops...
     ## Database authenticatable
     t.string :email, null: false, default: ""  #email input that only takes in 
                                                 strings as deafault and cant be 
                                                  empty
     t.string :encrypted_password, null: false, default: ""  #password input that
                                                              cant be empty and is 
                                                               a string




 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s