Coder Social home page Coder Social logo

toy_app's Introduction

##Exploration

Hartl Chapter 2: toy_app

##Eggs

  • Q: Create a new user, then use your browser’s HTML inspector to determine the CSS id for the text “User was successfully created.”

  • A: A flash notice saying "User was successfully created" pops up. It is contained within a div given id="notice".

  • Q: What happens when you refresh your browser?

  • A: The div with id="notice" is still present in the html code but contains no content.

  • Q: What happens if you try to create a user with a name but no email address?

  • A: The user object is created successfully. There is no validation that the email form is filled.

  • Q: What happens if you try create a user with an invalid email address, like “@example.com”?

  • A: The use object is created successfully. There is no validation that the email is a true one.

  • Q: Does Rails display a message by default when a user is destroyed?

  • A: Yes - there is also a flash notice on create, update and destroy.


  • Q: Write out the analogous steps for visiting the URL /users/1/edit.

  • A: The GET /users/1/edit request is parsed by the rotuer and the Users controller is called on. The controller evokes the edit action and, after conferring with the model (who interacts with the database), assigns the data to an instance variable. This instance variable is then used within the edit.html.erb view.

  • Q: Find the line in the scaffolding code that retrieves the user from the database in the previous exercise.

  • A:

# ./app/controller/users_controller.rb
class UsersController < ApplicationController
  def edit
  end
end
# ./app/models/user.rb
class User < ApplicationRecord
end
  • Q: What is the name of the view file for the user edit page?
  • A: toy_app/app/views/users/edit.html.erb

  • Q: Edit the user show page to display the content of the user’s first micropost.
  • A:
<!-- ./app/views/users/show.html.erb -->
<p>
    <%= @user.microposts.first.content %>
</p>
  • Q: Adding validation for the presence of micropost content ensures that microposts can’t be blank. Verify this behaviour.

  • A: A div contains #error_explanation; labels, input and textarea contain .field_with_errors. Note the difference of id and class.

  • Q: Validate the presence of name and email attributes in the User model

  • A:

# ./app/models/user.rb
class User < ApplicationRecord
  validates :name, presence: true
  validates :email, presence: true
end

toy_app's People

Contributors

csrail avatar

Stargazers

 avatar  avatar  avatar

Watchers

 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.