Giter Site home page Giter Site logo

rails-index-show-new-create-lab's Introduction

Index, Show, New, Create Lab

Objectives

  1. Build a RESTful index action
  2. Build a RESTful show action
  3. Build a RESTful new action
  4. Build a RESTful create action
  5. Link pages using route helpers
  6. Use route helpers in a redirect_to
  7. Build 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 create action

  • Linking 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.

Note: 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 coupons table with coupon_code and store columns, which should both be of the string data type.

  • Your index page should show all of the coupons in the database using the following format:

    coupon_code | store_name

  • The coupon codes on the index page should link to their corresponding coupon show page. You should use the link_to method and route helper methods instead of hard-coding an HTML <a> tag.

  • Your show page should render the specific coupon passed to the route. E.g., coupons/4 should show the coupon with an ID of 4.

  • The new.html.erb view template should render a form that uses the form_tag method.

  • The form should be wired up to the create action in the controller and, when submitted, should create a new record in the coupons table with the parameters passed through the form.

  • The controller should use the redirect_to helper method to redirect the user to the show page template for the newly-created coupon.

Resources

rails-index-show-new-create-lab's People

Contributors

annjohn avatar dakotalmartinez avatar danielseehausen avatar dependabot[bot] avatar ihollander avatar jmburges avatar jordanhudgens avatar lizbur10 avatar maxwellbenton avatar mhornbacher avatar peterbell avatar pletcher avatar realandrewcohn avatar rrcobb avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rails-index-show-new-create-lab's Issues

connection

It wont connect to the repo from the site.

No secrets template included

There is no secrets config template file included in this lesson as stated in the lesson.

config/secrets-template.yml

This uses rails 5.0

everytime when doing "learn", i get hit with a "DEPRECATION WARNING: You didn't set secret_key_base. Read the upgrade documentation to learn more about this new config option." error.

Everything is made with Rails 5.0 so difficult to solve the problem.

missing secrets.yml

Hello.get an error when running my tests.

Missing secret_token and secret_key_base for 'test' environment, set these values in config/secrets.yml.

Two conflicting tests for the index page

The test Multiple coupons are shown expects the store name as the link, while the test linking from the index page to the show page expects the coupon_code to be the link. It seems this issue still persists.

Expects coupon.store as the link

describe 'Multiple coupons are shown' do
  it 'on the index page' do
    Coupon.create(coupon_code: "ASD123", store: "Chipotle")
    Coupon.create(coupon_code: "XYZ098", store: "Jamba")
    visit coupons_path
    expect(page).to have_content(/Chipotle|Jamba/)
  end
end

expects coupon.coupon_code as the link

describe 'linking from the index page to the show page' do
  it 'index page coupon code text is hyperlinked to coupon page' do
    linked_coupon = Coupon.create(coupon_code: "FREESTUFF", store: "Chipotle")
    visit coupons_path
    expect(page).to have_link(linked_coupon.coupon_code, href: coupon_path(linked_coupon))
  end
end

coupons_controller_spec.rb has inconsistent params as rest of lab

Passing in the params hash in lines 9 and 14 as a nested hash { :coupon => { :coupon_code => "ASD123", :store => "Dean and Deluca" } } is inconsistent with the way the params are being created in the views in the solution code.

Changing the spec in lines 9 and 14 to { :coupon_code => "ASD123", :store => "Dean and Deluca" } fixes this issue.

missing secret_key_base

For some reason the file is labeled secrets_template.yml instead of secrets.yml and the tests come up with an error because it can't properly locate secrets.yml to find the secret_key_base

Gem file is all funked up

Had to switch sqlite version in gemfile and install an old version of bundler to get gem files installed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.