For this assessment i created a CRUD, MVC Shoes app using Sinatra. This app is a custom app that is created to track shoes. Essentially, its a Content Management System CMS. It allows the user to input and display category, size and brand of the shoes. A user is able to add, update, delete and list all shoes, shoe brand, shoe category and shoe size. This is how all four CRUD actions were implemented :
Now that we have the database and model set up, it's time to set up the ability to create shoes.
After a route in controller was created, get '/articles/new', that renders the new.erb view.
We need to create an ERB file in the views directory, new.erb, with a form that POSTs to a controller action, /articles. The controller action should use the Create CRUD action to create the article and save it to the database. When the form on new.erb is submitted, the action, pointing to /articles, will redirect to another action which will trigger a render of a show.erb file automatically. Before we can fully test if our form is working, we need to create that show.erb file, as our site will currently crash upon submission.
The Read CRUD action corresponds to two different controller actions: show and index. The show action should render the ERB view show.erb, which shows an individual show. The index action should render the ERB view index.erb, which shows a list of all of the shoes.
Create the get '/shoes' controller action. This action should use Active Record to grab all of the shoes and store them in an instance variable, @shoes. Then, it should render the index.erb view. That view should use ERB to iterate over @shoes and render them on the page.
The Update CRUD action corresponds to the edit controller action and view.
The Delete CRUD action corresponds to the delete controller action, delete '/shoes/:id'. To initiate this action, we'll add a "delete" button to the show page.
- Build an MVC Sinatra application.
- Use ActiveRecord with Sinatra.
- Use multiple models.
- Use at least one
has_many
relationship on a User model and onebelongs_to
relationship on another model. - Must have user accounts - users must be able to sign up, sign in, and sign out.
- Validate uniqueness of user login attribute (username or email).
- Once logged in, a user must have the ability to create, read, update and destroy the resource that
belongs_to
user. - Ensure that users can edit and delete only their own resources - not resources created by other users.
- Validate user input so bad data cannot be persisted to the database.