Giter Site home page Giter Site logo

validations-with-form_tag-rails-lab-v-000's Introduction

Validations with form_tag

Objectives

  • Render or redirect based on validation of instance in create/update
  • Prefill in form values based on an instance
  • Print out full error messages based on an invalid instance
  • Introspect on errors for a field
  • Apply an error class to a field conditionally based on errors on a field

Requirements

Validations

  1. Add validations to Author such that...
  2. name is not blank
  3. email is unique
  4. phone_number is exactly 10 digits long
  5. Add validations to Post such that...
  6. title is not blank
  7. content is at least 100 characters long
  8. category is either "Fiction" or "Non-Fiction"

Basic Routes & Controllers

  1. Create controllers for both models.
  2. Create show, new, edit, create, and update routes for both models.
  3. Define controller actions for show, new, and edit.
  4. Define the "valid path" for the create and update controller actions.
  5. Define the "invalid path" for the create and update controller actions.

Forms

  1. Create forms with form_tag for both models' new and edit actions.
  2. Prefill already-submitted forms with the invalid data when re-rendering.
  3. Display a list of errors at the top of forms when an invalid action is attempted. They should be contained in an element with id error_explanation, and each error should have its own <li>.
  4. Conditionally wrap each field in a .field_with_errors div if it has errors.

View Validations with form_tag on Learn.co and start learning to code for free.

validations-with-form_tag-rails-lab-v-000's People

Contributors

changemewtf avatar pletcher avatar ghaash avatar jmburges avatar mendelb avatar aviflombaum avatar

Watchers

James Cloos avatar

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.