Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed changes to remove redundant code and preserve memoization #5

Merged
merged 4 commits into from Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/application_controller.rb
Expand Up @@ -95,12 +95,12 @@ class ApplicationController < Sinatra::Base
end

helpers do
def logged_in?
def is_logged_in?
!!session[:user_id]
end

def current_user
User.find(session[:user_id])
@user ||= User.find(session[:user_id])
end
end

Expand Down
14 changes: 7 additions & 7 deletions app/models/helpers.rb
@@ -1,11 +1,11 @@
require 'sinatra/base'

class Helpers
def self.current_user(args)
@user ||= User.find(args[:user_id])
end
# def self.current_user(args)
# @user ||= User.find(args[:user_id])
# end

def self.is_logged_in?(args)
args.include?(:user_id)
end
end
# def self.is_logged_in?(args)
# args.include?(:user_id)
# end
end
4 changes: 2 additions & 2 deletions app/views/home.erb
Expand Up @@ -8,7 +8,7 @@
<body>
<section id="particles-js">
<div id="main">
<% if Helpers.is_logged_in?(session) %>
<% if is_logged_in? %>
<h1>Welcome</h1>
<h3 id="home-buttons"><a href="/new">New Task</a> | <a href="/show">Show Task</a></h3>
<h3 id="logout-home"><a href="/logout">Log Out</a></h3>
Expand All @@ -19,4 +19,4 @@
</div>
</section>
</body>
</html>
</html>