For this lab, we'd like you to create a small application that mimics a very minialistic shopping site. The application should allow users to sign up and login and then see a list of products and create orders which are different combinations of products
-
Examine the code provided and take a look at the routes, migrations and controllers. Before migrating - add the following to the models:
-
A User should have a:
- username (this should always be unique)
- password (this should be at least 5 characters)
- password_digest (this is for
has_secure_password
) - is_admin (a boolean which by default is false)
-
A Product should have a:
- name (this should always be present)
- category
- price
-
An Order should have a:
- name (this should always be present)
-
Start setting up your associations (a user can make many orders, many orders have many different products and many different products can belong to many different orders)
-
Use
has many through
for your many to many association. -
Test your models, associations and validations in rails console before continuing.
- Start by building a simple log in system using
has_secure_password
and sessions. - Your login form should have a password confirmation field
- When a user logs in, if they are not an admin, they should see a list of products and have the option to create a new order and see their existing orders
- If the user is an admin, they should be able to perform full CRUD on the products.
- When a user goes to create a new order, they should see a list of all of the products and be able to add how ever many products they like to each other (use checkboxes for this - review the cookbook app to see how this was done)
BONUS
- Ensure that users can only see their orders unless they are an admin.
- Allow admin's to view a list of all of the users.
- Allow users to change their personal information (username and password).
- Show the total price of the order when a users sees their orders.
- Convert
routes.rb
to use (nested?) resources to generate the routes.