Controllers - aamarill/Take-Home-Pay GitHub Wiki
Summary
This page describes each controller and its methods in detail.
Application Controller
This is the controller that inherits from the Rails base controller. This controller is created by default when a Rails project is created.
Methods
after_sign_in_path_for(resource_or_scope)
This method specifies the path to redirect to after signing in. This method executes after signing in. This redirecting method is necessary because the root
path is the path to creating a new session. So, without this method, Rails would try to render a new session but Devise would redirect to the root
since a user is already signed in so Rails would try to render the root
session which, again, that's the new session
view. In short, without this method, Rails goes through an infinite loop of redirections.
Statements Controller
This controller is in charge of handling all actions related to the statements. For example, showing all of the user's statements, creating and deleting statements etc.
This controller includes CalculationsHelper
and ensures an authenticated user is present before performing any action.
Methods
index
Display all of the statements associated with the user.
new
Render new.html.erb
with the information contained in the last statement. If there are no statements created, simply create a new instance and use that to populate a blank form.
create
Update the information contained within the _calculations.html.erb
partial.
If the user selected to create a new statement on the form in `_calculator.html.erb', create a new statement.
show
Verify the user using the verify_user
method.
Display a specific statement, if that statement belongs to the user that is making the request.
destroy
Finds the statement that needs to be deleted, and deletes it. If the statement to be deleted is not found, it displays a notice to the user and redirects the user to the index page.
get_statement
Looks for a specific statement using its id
attribute. If not found, a notice is flashed to the user and it is redirected to the index view. Otherwise, the method returns the statement found.
verify_user
This method verifies the params
object to see if the id
attribute within it matches the id
of the user that is currently logged in. This is necessary because otherwise, any user would be able to see statements from another user. For us, the desired behavior is that users can only see statements they own.