Rails Crash Course: A No-Nonsense Guide to Rails Development

Rails Crash Course: A No-Nonsense Guide to Rails Development

Language: English

Pages: 296

ISBN: 1593275722

Format: PDF / Kindle (mobi) / ePub


Rails is a robust, flexible development platform that lets you build complex websites quickly. Major websites like GitHub, Hulu, and Twitter have run Rails under the hood, and if you know just enough HTML and CSS to be dangerous, Rails Crash Course will teach you to harness Rails for your own projects and create web applications that are fast, stable, and secure.

In Part I, you'll learn Ruby and Rails fundamentals and then dive straight into models, controllers, views, and deployment. As you work through the basics, you'll learn how to:

  • Craft persistent models with Active Record
  • Build view templates with Embedded Ruby
  • Use Git to roll back to previous versions of your code base
  • Deploy applications to Heroku

In Part II, you'll take your skills to the next level as you build a social networking app with more advanced Ruby tools, such as modules and metaprogramming, and advanced data modeling techniques within Rails's Active Record. You'll learn how to:

  • Implement an authentication system to identify authorized users
  • Write your own automated tests and refactor your code with confidence
  • Maximize performance with the asset pipeline and turbolinks
  • Secure your app against SQL injection and cross-site scripting
  • Set up a server and deploy applications with Capistrano

Each chapter is packed with hands-on examples and exercises to reinforce what you've learned. Whether you're completely new to Ruby or you've been mucking around for a bit, Rails Crash Course will take you from the basics to shipping your first Rails application, fast.

 

 

 

 

 

 

 

 

 

 

 

your application. Note Because these files usually do not need to be saved, version control systems ignore them. The vendor Directory Finally, the vendor directory holds assets needed by third-party gems that you add to your application. Its purpose is similar to the lib directory, except it is used by libraries that you did not write yourself. Rails Commands You use four different command-line programs when building Rails applications. These can sometimes be confusing to new Rails

We had to use multiple commands this time, but just like before, we’ve created a brand new Post object. Two posts are now stored in the database. In both examples, we only assigned values to the post’s title attribute, but you would assign values to the post body in exactly the same way. Rails assigns values to id, created_at, and updated_at automatically. You shouldn’t change these. Models   31 Read Once you have a few posts in your database, you’ll probably want to read them back out for

add these actions:    class SessionsController < ApplicationController def new end def create user = User.find_by(email: params[:email]) if user && user.authenticate(params[:password]) session[:user_id] = user.id redirect_to root_url, notice: "Log in successful!" else flash.now.alert = "Invalid email or password" render "new" end end def destroy session[:user_id] = nil redirect_to root_url, notice: "Log out successful!" end end The new method  renders the login form. The controller action

--snip-post 'follow/:id', to: 'users#follow', as: 'follow_user' --snip-- Now update the link in app/views/users/show.html.erb to use the POST method instead of the default GET: <%= link_to "Follow", follow_user_path(@user), method: :post, class: "btn btn-default" %> With these two changes, the follow action should now be safe from CSRF attacks. Security   171 Summary Malicious users and sites are unavoidable on the Web today. As your application gains popularity, the risk of attack rises.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Download sample

Download