Index, Show, New, Create Lab
Objectives
Build a RESTful
indexactionBuild a RESTful
showactionBuild a RESTful
newactionBuild a RESTful
createactionLink pages using route helpers
Use route helpers in a
redirect_toBuild a new form with a
form_tag
Instructions
This will be a pretty extensive lab that will combine a number of the concepts that we have reviewed, including:
Drawing multiple route types
Integrating route helper methods
Building out a form and wiring it up to the
createactionLinking pages together
In this lab, the application you will be starting out with will be completely blank. There are no models, views, controllers, et cetera. It has a number of RSpec and Capybara tests that will all need to pass to complete the lab. The tests can be found in the spec directory, in the models, features, and controllers sub-directories. Feel free to walk through the specs to see what behavior the application should have when you're done.
Like many production applications, we've included the config/secrets.yml file in the .gitignore. This means that you are going to have to create your own config/secrets.yml file for the application to run. Don't worry- we've given you a template. Just rename config/secrets-template.yml to config/secrets.yml, and you should be able to get the application to run.
The application you will be building is a Coupon app. Below is a high-level overview of the features you'll be building out:
You will need to create a
couponstable withcoupon_codeandstorecolumns, which should both be of thestringdata type.Your
indexpage should show all of the coupons in the database.The coupon codes on the
indexpage should link to their corresponding couponshowpage. You should use thelink_tomethod and route helper methods instead of hard-coding an HTML<a>tag.Your
showpage should render the specific coupon passed to the route. E.g.,coupons/4should show the coupon with an ID of 4.The
new.html.erbview template should render a form that uses theform_tagmethod.The form should be wired up to the
createaction in the controller and, when submitted, should create a new record in thecouponstable with the parameters passed through the form.The controller should use the
redirect_tohelper method to redirect the user to theshowpage template for the newly-created coupon.
Resources
Clone: https://github.com/learn-co-curriculum/rails-index-show-new-create-lab
Last updated