Ruby On Rails Classroom
Neha Jaggi /
Professional /
Web Technology
- Foreword to the First Edition
- Acknowledgments
- About the Author
- From Zero to Deploy
- Development Environments
- Ruby RubyGems Rails and Git
- The First Application
- rails server
- Model-view-controller MVC
- Version Control with Git
- What Good Does Git Do You
- GitHub
- Branch Edit Commit Merge
- Deploying
- Heroku Setup
- Conclusion
- A Demo App
- Planning the Application
- Modeling Demo Users
- Modeling Demo Microposts
- The Users Resource
- A User Tour
- MVC in Action
- Weaknesses of this Users Resource
- The Microposts Resource
- A Micropost Microtour
- Putting the micro in Microposts
- A User has many Microposts
- Inheritance Hierarchies
- Deploying the Demo App
- Conclusion
- Static Page
- Mostly Static Pages
- Truly Static Pages
- Static Pages with Rails
- Our First Tests
- Test-driven Development
- Adding a Page
- Testing a Title Change
- Passing Title Tests
- Embedded Ruby
- Eliminating Duplication with Layouts
- Conclusion
- Advanced Setup
- Eliminating bundle exec
- Automated Tests with Guard
- Speeding up Tests with Spork
- Tests inside Sublime Text
- Rails-Flavored Ruby
- Strings and Methods
- Objects and Message Passing
- Method Definitions
- Other Data Structures
- Blocks
- Hashes and Symbols
- CSS revisited
- Ruby Classes-Constructors
- Class Inheritance
- Modifying Built-in Classes -A Controller Class
- A User Class
- Conclusion-Exercises
- Adding Some Structure
- Site Navigation
- Bootstrap and Custom CSS
- Partials
- Sass and the Asset Pipeline
- Syntactically Awesome Stylesheets
- Layout Links
- Route Tests
- Rails Routes
- Named Routes
- Pretty RSpec
- User Signup A First Step
- Signup URI
- Conclusion-Exercises
- Modeling Users
- User Model
- Database Migrations
- The Model File
- Creating User Objects
- Finding User Objects
- Updating User Objects
- User Validations
- Validating Presence
- Length Validation-Format Validation
- Uniqueness Validation
- Adding a Secure Password
- An Encrypted Password
- Password and Confirmation
- User Authentication
- User Has Secure Password
- Creating a User
- Conclusion-Exercises
- Showing Users
- Debug and Rails Environments
- A Users Resource
- Testing the User Show Page with Factories
- A Gravatar Image and a Sidebar
- Signup Form
- Tests for User Signup
- Using form for
- The Form HTML
- Signup Failure
- Signup Error Messages
- The Finished Signup Form
- The Flash
- Deploying to Production with SSL
- Conclusion-Exercises
- Sessions and Signin Failure
- Sessions Controller
- Signin Tests
- Signin Form
- Reviewing Form Submission
- Rendering with a Flash Message
- Signin Success
- Remember Me
- A Working sign in Method
- Current User
- Changing the Layout Links
- Signin upon Signup
- Signing Out
- Introduction to Cucumber Optional
- Installation and Setup
- Features and Steps
- Counterpoint RSpec Custom Matchers
- Conclusion-Exercises
- Updating Users
- Edit Form
- Unsuccessful Edits
- Successful Edits
- Authorization
- Requiring Signed-in Users
- Requiring the Right User
- Friendly Forwarding
- Showing All Users
- User Index
- Sample Users
- Pagination
- Partial Refactoring
- Deleting Users-Administrative Users
- The destroy Action
- Conclusion-Exercises
- A Micropost Model
- The Basic Model
- Accessible Attributes and the First Validation
- User Micropost Associations
- Micropost Refinements
- Content Validations
- Showing Microposts
- Augmenting the User Show Page
- Sample Microposts
- Manipulating Microposts
- Access Control
- Creating Microposts
- A Proto-feed
- Destroying Microposts
- Conclusion-Exercises
- Following Users
- The Relationship Model
- A Problem with the Data Model and a Solution
- User Relationship Associations
- Validations
- Followed users
- Followers
- Sample Following Data
- Stats and a Follow Form
- Following and Followers Pages
- A Working Follow Button the Standard Way
- A Working Follow Button with Ajax
- Making the output of find readable in shell
- CRUD Operation-Create
- The Status Feed
- Motivation and Strategy
- A First Feed Implementation
- Subselects
- The New Status Feed
- Conclusion
- Exercises
Ruby On Rails Lesson
Finding User Objects
Active Record provides several options for finding objects. Let’s use them to find the first user we created while verifying that the third user (foo) has been destroyed. We’ll
start with the existing user:
=> #<User id: 1, name: "Michael Hartl", email: "mhartl@example.com",
created at: "2011-12-05 00:57:46", updated at: "2011-12-05 00:57:46">
Here we’ve passed the id of the user to User.find; Active Record returns the user with that id.
Let’s see if the user with an id of 3 still exists in the database:
ActiveRecord::RecordNotFound: Couldn't find User with ID=3
Since we destroyed our third user in Section 6.1.3, Active Record can’t find it in the database. Instead, find raises an exception, which is a way of indicating an exceptional event in the execution of a program—in this case, a nonexistent Active Record id, which causes find to raise an ActiveRecord::RecordNotFound exception.8 In addition to the
generic find, Active Record also allows us to find users by specific attributes:
=> #<User id: 1, name: "Michael Hartl", email: "mhartl@example.com",
created at: "2011-12-05 00:57:46", updated at: "2011-12-05 00:57:46">
The find_by_email method is automatically created by Active Record based on the email attribute in the users table. (As you might guess, Active Record creates a find_by_name method as well.) Since we will be using email addresses as usernames, this sort of find will be useful when we learn how to let users sign in to our site (Chapter 7). If you’re worried that find_by_email will be inefficient if there are a large number of users, you’re ahead of the game; we’ll cover this issue, and its solution via database indices, in Section 6.2.5.
We’ll end with a couple of more general ways of finding users. First, there’s first:
=> #<User id: 1, name: "Michael Hartl", email: "mhartl@example.com",
created at: "2011-12-05 00:57:46", updated at: "2011-12-05 00:57:46">
Naturally, first just returns the first user in the database. There’s also all:
=> [#<User id: 1, name: "Michael Hartl", email: "mhartl@example.com",
created at: "2011-12-05 00:57:46", updated at: "2011-12-05 00:57:46">,
#<User id: 2, name: "A Nother", email: "another@example.org", created at:
"2011-12-05 01:05:24", updated at: "2011-12-05 01:05:24">]
No prizes for inferring that all returns an array (Section 4.3.1) of all users in the database.
Neha Jaggi
Skills Ruby On Rails
Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-
Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX).
Explore