-
Notifications
You must be signed in to change notification settings - Fork 11
Lab 2
Gannon McGibbon edited this page Sep 13, 2017
·
4 revisions
- Fork this project.
- Clone your forked project (
git clone https://github.com/winnipegrb/just_chew.git). - Check out the
lab_2_prepbranch (git checkout lab_2_prep). - Follow the steps in the README to get the app running (vagrant works with default configuration).
- Seed the database with
bundle exec rails db:seed.
- Open
app/controllers/locales_controller.rb. - In the
#findaction:
- Redirect to
/restaurantsvia therestaurants_pathhelper. - NOTE: Restaurant locale logic will be added in a future lab.
- Open
app/controllers/restaurants_controller.rb. - Replace the superclass of this controller with
OrderingController. - Create a
before_actioncallback for#load_restaurants. - Add a private method
#load_restaurants:
- Load all restaurants ordered by
:updated_at. - Assign the result of the restaurants query to
@restaurants.
- Open
app/controllers/menus_controller.rb. - Replace the superclass of this controller with
OrderingController. - Create
before_actioncallbacks for#load_restaurantand#load_menu. - Add a private
#load_restaurant:
- Load the restaurant matching the
:restaurant_idparameter. - Assign the result of the restaurant query to
@restaurant.
- Add a private
#load_menumethod:
- Load the menu that belongs to
@restaurant. - Assign the result of the menu query to
@menu.
- Open
app/controllers/profiles_controller.rb. - Using Clearance, create a
before_actioncallback to require users be logged in. - Add a private method
#user_paramsmethod:
- Require params have a
:userkey - Permit user params to change
:first_name,:last_name,:email, and:passwordattributes. - NOTE:
Clearance.configuration.user_parametermay be used in place of the user key. - NOTE:
Clearance::UsersController::PARAMSmay be used in place of the user attributes.
- In the
#updateaction:
- Update the currently logged in user with
#user_params. - If the update operation was successful:
- render the
:showview with the200 OKstatus code.
- render the
- If the update operation was not successful:
- render the
:showview with the422 UNPROCESSABLE ENTITYstatus code.
- render the
- Open
app/controllers/order/preferences_controller.rb. - Replace the superclass of this controller with
ApiController. - Using Clearance, create a
before_actioncallback to require users be logged in. - Create a
before_actioncallback for#load_order_preference. - Add a private
#load_order_preferencemethod:
- Load the currently logged in user's order preference.
- Assign the result of the order preference query to
@order_preference.
- Add a private
#order_preference_paramsmethod:
- Require params have a
:order_preferencekey - Permit order preference params to change the
:typeattribute.
- In the
#updateaction:
- Update
@order_preferencewith#order_preference_params. - If the update operation was successful:
- render the
@order_preferenceas JSON with the200 OKstatus code.
- render the
- If the update operation was not successful:
- render the
@order_preference's errors as JSON with the422 UNPROCESSABLE ENTITYstatus code.
- render the
Once you've completed all lab sections, run the project's test suite with bundle exec rspec. Once RSpec is finished, you will receive a percentage mark based on what tests pass and fail. If you got anything wrong, don't give up! Keep refactoring your code until all tests are passing.
- https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Classes
- http://api.rubyonrails.org/classes/ActionController/Redirecting.html
- http://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-order
- http://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html
- http://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-find
- https://github.com/thoughtbot/clearance#use
- http://api.rubyonrails.org/classes/ActionController/StrongParameters.html
- http://guides.rubyonrails.org/layouts_and_rendering.html#using-render