Commit f5ff1994 authored by John Noel's avatar John Noel

Finished Devise User model setup

parent cab3fb7e
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
......@@ -3,4 +3,4 @@
*= require_self
*/
@import "bootstrap";
body { padding-top: 5rem; }
\ No newline at end of file
#container { padding-top: 5rem; }
\ No newline at end of file
// Place all the styles related to the Publics controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class ApplicationController < ActionController::Base
protected
def after_sign_in_path_for(resource)
# if resource.is_a?(AdminUser)
# # Go to this page
# elsif resource.is_a?(User)
# # Go to this page instead
# end
authenticated_root_url
end
def after_sign_up_path_for(resource)
authenticated_root_url
end
def after_sign_out_path_for(resource)
unauthenticated_root_url
end
end
\ No newline at end of file
class PostsController < ApplicationController
before_action :authenticate_user!
def index
@posts = Post.all
end
......
class PublicsController < ApplicationController
def index
end
end
module PublicsHelper
end
......@@ -12,7 +12,29 @@
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<%= link_to "Blog App", root_path, class: "navbar-brand" %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
</ul>
<span class="navbar-text">
<% if user_signed_in? %>
Logged in as <strong><%= current_user.email %></strong>.
<%= link_to 'Edit profile', edit_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class => 'navbar-link' %>
<% else %>
<%= link_to "Sign up", new_user_registration_path, :class => 'navbar-link' %> |
<%= link_to "Login", new_user_session_path, :class => 'navbar-link' %>
<% end %>
</span>
</div>
</nav>
<div class="container" id="container">
<% if notice %>
<p class="alert alert-success"><%= notice %></p>
<% end %>
......
<div class="row">
<div class="col">
<h3>Sign Up</h3>
<%= simple_form_for :user, url: registration_path(:user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.button :submit, "Sign Up" %>
<% end %>
</div>
<div class="col">
<h3>Log In</h3>
<%= simple_form_for :user, url: session_path(:user) do |f| %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.button :submit, "Log In" %>
<% end %>
</div>
</div>
\ No newline at end of file
Rails.application.routes.draw do
devise_for :users
devise_scope :user do
authenticated :user do
resources :posts
root to: 'posts#index', as: :authenticated_root
end
unauthenticated :user do
root to: 'publics#index', as: :unauthenticated_root
end
end
root to: 'posts#index'
end
\ No newline at end of file
require 'test_helper'
class PublicsControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
get publics_index_url
assert_response :success
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment