Coder Social home page Coder Social logo

validations-in-controller-actions-rails-lab's Introduction

Validations In Controller Actions Lab

Time to apply these new tools!

The goal of this lab is to allow users of this blog-style application to create and edit authors and posts without worrying about typos or other mistakes leading to error-prone form submissions.

For example, if someone creates a blog post with less than 100 characters of content, it's likely that they accidentally pasted the wrong text, or misunderstood which information goes into which field. We can improve the user's experience and the stability of our codebase by notifying users about these kinds of mistakes before bad data gets into the database.

Objectives

  • Define validations on a model
  • Use a conditional statement in an action to render different responses based on the validation state of a model
  • Re-render a form with validation errors
  • Validate a create action
  • Validate an update action

Requirements

Make sure you run rake db:seed so you have some data to work with (defined in db/seeds.rb).

This is a barebones app with two models, Author and Post. Right now, you can...

To complete this lab, you will need to:

  1. Add validations to Author such that...
  2. The name cannot be blank
  3. The e-mail is unique
  4. Add validations to Post such that...
  5. The title cannot be blank
  6. The category is either "Fiction" or "Non-Fiction"
  7. The content is at least 100 characters long.
  8. Change AuthorsController#create to re-render the form if the new author is invalid.
  9. Change PostsController#update to re-render the form if the updated post is invalid.

validations-in-controller-actions-rails-lab's People

Contributors

annjohn avatar aviflombaum avatar changemewtf avatar danielseehausen avatar dependabot[bot] avatar franknowinski avatar ihollander avatar jmburges avatar lizbur10 avatar lkwlala avatar maxwellbenton avatar pletcher avatar rrcobb avatar

Watchers

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

validations-in-controller-actions-rails-lab's Issues

weird line breaks

I'm not sure the cause, but there's weird line breaks in this lesson for me.
Chrome ://version
Google Chrome 49.0.2623.87 (Official Build) (64-bit)
Revision d177478d466b84ab06f0f48081fc30e3b04be6ca-refs/branch-heads/2623@{#592}
OS Linux

Migration errors

The two migration files in this lab do not have the Migration[4.2] designation which leads to errors when you try to migrate. I added the [4.2] to the end to get everything to work.

ThreadError: already initialized occurring with Ruby 2.6 and rails < 5

Summary: Students are experiencing a ThreadError: already initialized when attempting learn tests when using Ruby 2.6 and Rails 4.2 (or any Rails < 5). It seemed to be associated with this github issue

Repeatability: After fixing a sub-issue with this lab (deleting the Gemfile.lock and specifying gem 'sqlite3', '~> 1.3.6' in the Gemfile), this problem is repeatable by running this lab with Ruby 2.6. Note that it is probably prudent to also fix the sqlite3 Gemfile/Gemfile.lock issue.

Solution: Updating to Rails 5 (in Gemfile) and changing the rspec tests so that all params passed to a route are in a nested hash `{params: { params1: value1, params2: value2}} solved the issue.

Why? Author.create!(author_params)

The lab provides @author = Author.create!(author_params) as the def create info for author class controller, but if we are not going to use it why provide it all.

Thanks

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.