Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
schedules
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
11
Issues
11
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
schedules
Commits
63cb1356
Commit
63cb1356
authored
Feb 08, 2019
by
Zac Wood
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unnecessary redirect from application_controller
parent
7b640f2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
schedules/.rubocop.yml
schedules/.rubocop.yml
+3
-0
schedules/app/controllers/application_controller.rb
schedules/app/controllers/application_controller.rb
+22
-8
No files found.
schedules/.rubocop.yml
View file @
63cb1356
...
...
@@ -16,3 +16,6 @@ Metrics/BlockLength:
Style/ClassAndModuleChildren
:
Enabled
:
false
Style/GuardClause
:
Enabled
:
false
schedules/app/controllers/application_controller.rb
View file @
63cb1356
# Configures the application.
class
ApplicationController
<
ActionController
::
Base
protect_from_forgery
with: :null_session
before_action
:set_semester
,
:set_cookies
,
:set_cart
# On each request, set the semester and cart.
before_action
:set_semester
,
:set_cart
# Every page needs to know what semester it should load data from.
# set_semester checks both the semester_id query parameter and the user's cookies
# to look for a semester id and loads whatever it finds into @semester.
#
# By default, load the most recent semester.
def
set_semester
if
params
.
key?
(
:semester_id
)
cookies
[
:semester_id
]
=
params
[
:semester_id
]
@semester
=
Semester
.
find_by_id
params
[
:semester_id
]
cookies
[
:semester_id
]
=
@semester
.
id
elsif
cookies
[
:semester_id
].
nil?
redirect_to
(
url_for
(
params
.
permit
(
params
.
keys
).
merge
(
semester_id:
Semester
.
first
.
id
)))
@semester
=
Semester
.
first
cookies
[
:semester_id
]
=
@semester
.
id
else
redirect_to
(
url_for
(
params
.
permit
(
params
.
keys
).
merge
(
semester_id:
cookies
[
:semester_id
])))
@semester
=
Semester
.
find_by_id
cookies
[
:semester_id
]
end
end
# The user's cart is stored as a JSON-encoded list of CRNs.
# set_cart sets the @cart variable, which is a list of the sections represented by the CRNs.
def
set_cart
# set the cart cookie to be empty if it doesn't already exist
cookies
.
permanent
[
:cart
]
=
"[]"
if
cookies
.
permanent
[
:cart
].
nil?
# decode the JSON list into an array
@cart
=
JSON
.
parse
(
cookies
.
permanent
[
:cart
])
# get rid of any invalid CRNs
@cart
=
@cart
.
reject
{
|
crn
|
CourseSection
.
find_by_crn
(
crn
).
nil?
}
cookies
.
permanent
[
:cart
]
=
@cart
.
to_json
end
def
set_cookie
s
cookies
.
permanent
[
:cart
]
=
"[]"
if
cookies
.
permanent
[
:cart
].
nil?
# set the cookie to the JSON-encoded list of valid section
s
cookies
.
permanent
[
:cart
]
=
@cart
.
to_json
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment