Rails 4 Application Development HOTSHOT


Rails 4 Application Development HOTSHOT
eBook: $29.99
Formats: PDF, PacktLib, ePub and Mobi formats
$25.50
save 15%!
Print + free eBook + free PacktLib access to the book: $79.98    Print cover: $49.99
$75.49
save 6%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Also available on:
Overview
Table of Contents
Author
Support
Sample Chapters
  • Build interesting application scenarios with Rails 4
  • Upgrade your knowledge for the latest changes in the Rails framework
  • Follow the project-based approach to building applications from simple to advanced skill levels

Book Details

Language : English
Paperback : 378 pages [ 235mm x 191mm ]
Release Date : April 2014
ISBN : 1783286296
ISBN 13 : 9781783286294
Author(s) : Saurabh Bhatia
Topics and Technologies : All Books, Open Source


Table of Contents

Preface
Project 1: A Social Recipe-sharing Website
Project 2: Conference and Event RSVP Management
Project 3: Creating an Online Social Pinboard
Project 4: Creating a Restaurant Menu Builder
Project 5: Building a Customizable Content Management System
Project 6: Creating an Analytics Dashboard using Rails and Mongoid
Project 7: Creating an API Mashup – Twitter and Google Maps
Project 8: API Only Application – Backend for a Mobile App
Project 9: Video Streaming Website using Rails and HTML5
Project 10: A Rails Engines-based E-Commerce Platform
Index
  • Project 1: A Social Recipe-sharing Website
    • Mission briefing
    • Creating mockups
    • Adding test data and creating tests
    • Adding categories
    • Creating and adding recipes
    • Creating associations – recipes and categories
    • Adding authentication
    • Beautifying your views
    • Mission accomplished
    • Hotshot challenges
  • Project 2: Conference and Event RSVP Management
    • Mission briefing
    • Creating and administrating events
    • Creating search-friendly URLs for events
    • Adding tags to events
    • Tagging-based search and tag cloud
    • Adding Gravatar for a user
    • Creating RSVPs for events
    • Adding event moderation
    • Creating "My events" to manage events created by users
    • Mission accomplished
    • Hotshot challenges
  • Project 3: Creating an Online Social Pinboard
    • Mission briefing
    • Creating file uploads and image resizing
    • Creating an infinitely scrollable page
    • Creating a responsive grid layout
    • Adding a full-text search
    • Resharing the pins and creating modal boxes using jQuery
    • Enabling the application to send a mail
    • Securing an application from cross-site scripting or XSS
    • Mission accomplished
    • Hotshot challenges
  • Project 4: Creating a Restaurant Menu Builder
    • Mission briefing
    • Creating organizations with sign up
    • Creating restaurants, menus, and items
    • Creating user roles
    • Creating plans
    • Creating subdomains
    • Adding multitenancy and reusable methods
    • Creating a monthly payment model, adding a free trial plan, and generate a monthly bill
    • Exporting data to a CSV format
    • Mission accomplished
    • Hotshot challenges
  • Project 5: Building a Customizable Content Management System
    • Mission briefing
    • Creating a separate admin area
    • Creating a CMS with the ability to create different types of pages
    • Managing page parts
    • Creating a Haml- and Sass-based template
    • Generating the content and pages
    • Implementing asset caching
    • Mission accomplished
    • Hotshot challenges
  • Project 6: Creating an Analytics Dashboard using Rails and Mongoid
    • Mission briefing
    • Creating a MongoDB database
    • Creating a click-tracking mechanism
    • Creating a visit-tracking mechanism
    • Writing map-reduce and aggregation to fetch and analyze data
    • Creating a dashboard to display clicks and impression values
    • Creating a line graph of the daily click activity
    • Creating a bar graph of the daily visit activity
    • Creating a demographic-based donut chart
    • Mission accomplished
    • Hotshot challenges
  • Project 7: Creating an API Mashup – Twitter and Google Maps
    • Mission briefing
    • Creating an application login with Twitter
    • Calling all Twitter friends
    • Getting latitude and longitude details of the user's location
    • Passing Twitter data to the Google Maps API using Rails
    • Displaying friends on the map using the Google API
    • Creating points of interest – filter users based on their location
    • Mission accomplished
    • Hotshot challenges
  • Project 10: A Rails Engines-based E-Commerce Platform
    • Mission briefing
    • Creating a category and product listing
    • Creating a shopping cart and an Add to Cart feature
    • Packaging the engine as a gem
    • Mounting the engine on a blank Rails application
    • Customizing and overriding the default classes
    • Mission accomplished
    • Hotshot challenges

Saurabh Bhatia

Saurabh Bhatia has been developing professional software since 2005. However, his programming interests date back to his school days. Starting with Java, he quickly moved to Ruby on Rails in 2006, and it has been his primary choice of development framework since then. He built a Ruby on Rails consulting company and ran it for five years. He has worked with several companies in the tech industry, from getting two-person startups off the ground to developing software for large corporates. He is currently the CTO of Ruling Digital Inc., a software company that develops software for universities.

He has been an open source enthusiast and has helped Ubuntu penetrate the Indian market since 2007. He was a part of the open source promotion society called Twincling Society for Open Source in Hyderabad. He started and moderated Bangalore Ruby Users Group and also moderates the Mumbai Ruby Users Group. He is also a part of the RailsBridge initiative for mentoring new Rails developers.

Over the years, he has written several articles online and in print for different publications, such as Linux User and Developer, Linux For You, Rails Magazine, Developer.com (http://www.developer.com/), and SitePoint Ruby (http://www.sitepoint.com/ruby/). He currently resides in Taiwan. He wishes to continue writing and share his knowledge as much as possible with budding developers.

Sorry, we don't have any reviews for this title yet.

Code Downloads

Download the code and support files for this book.


Submit Errata

Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.


Errata

- 17 submitted: last submission 08 Jul 2014

On Page 28,

 

The given code is: 

 

<div class="form-group">

<%= f.label :food_preference %><br>

<%= f.select(:food_preference_id, 

options_from_collection_for_select(FoodPreference.all, 

:id, :name), {:prompt => 'Please Choose'}, :class => 

"form-control") %>

</div>

<div class="form-group">

<%= f.label :food_type %><br>

<%= f.select(:food_type_id, 

options_from_collection_for_select(FoodType.all, :id, 

:name), {:prompt => 'Please Choose'}, :class => "formcontrol") %>

</div>

<div class="form-group">

<%= f.label :cuisine %><br>

<%= f.select(:cuisine_id, 

options_from_collection_for_select(Cuisine.all, :id, 

:name), {:prompt => 'Please Choose'}, :class => "formcontrol") %>

</div>

 

 

It should be:

app/views/recipes/_form.html.erb

<div class="form-group">

<%= f.label :food_preference %><br>

<%= f.select(:food_preference_id,

options_from_collection_for_select(FoodPreference.all,

:id, :name), {:prompt => 'Please Choose'}, :class =>

"form-control") %>

</div>

<div class="form-group">

<%= f.label :food_type %><br>

<%= f.select(:food_type_id,

options_from_collection_for_select(FoodType.all, :id,

:name), {:prompt => 'Please Choose'}, :class => "form-control") %>

</div>

<div class="form-group">

<%= f.label :cuisine %><br>

<%= f.select(:cuisine_id,

options_from_collection_for_select(Cuisine.all, :id,

:name), {:prompt => 'Please Choose'}, :class => "form-control") %>

</div>

On Page 30,

 

The given code is: 

 

app/models/recipe.rb

class Recipe < ActiveRecord::Base

  belongs_to :food_type

end

 

It should be:

 

app/models/recipe.rb

class Recipe < ActiveRecord::Base

  belongs_to :food_type

  belongs_to :food_preferences

  belongs_to :cuisine

end

On page 50

 

The third bullet point is now showing as:

 

We will then enable slug creation on a model. After adding a column for slugs, we 

need to enable slugging in the model as follows:

 

extend FriendlyId

friendly_id :title, use: :slugged

 

This will create a slug based on the title of the event. However, if the slug history 

feature is not enabled, the old URLs will give 404s. In order to maintain the old URLs 

intact, we need to enable history.

 

 

It should be:

 

We will then enable slug creation on a model. After adding a column for slugs, we 

need to enable slugging in the model as follows:

 

extend FriendlyId

friendly_id :title, use: :slugged

 

This will create a slug based on the title of the event. However, if the slug history 

feature is not enabled, the old URLs will give 404s. In order to maintain the old URLs 

intact, we need to enable history.

 

We will have to modify the set_event method to look for friendly_id slugs instead of id:

 

private

# Use callbacks to share common setup or constraints between actions.

def set_event

@event = Event.friendly.find(params[:id])

end 

On page 24

The given code is 

rails g model food_preference

It should be:

rails g model food_preference name:string 

 

On page 27

The third point is:

 

We can now see what we have already created. In order to see what we have 

created so far, let's fire up our server and see what we just created by navigating 

to localhost:3000.

 

It should be: 

We can now see what we have already created. In order to see what we have 

created so far, let's fire up our server and see what we just created by navigating 

to localhost:3000/recipes/new

 

On Page 37, step 13
Step 13 is now showing as:
Now we'll look at how to style sublinks and wrap them into Rails' loops:
Our left bar for displaying categories can be displayed as a panel with several
sublinks. These are generated in loop using the Rails' each loop. We will first define
the values for the sidebar in our application_controller.rb file:
app/controllers/application.rb
helper_method :sidebar_values
def sidebar_values
    @food_preferences = FoodPreference.all 
    @food_types = FoodType.all
    @cuisines = Cuisine.all
end
It should be:
Now we'll look at how to style sublinks and wrap them into Rails' loops:
Our left bar for displaying categories can be displayed as a panel with several
sublinks. These are generated in loop using the Rails' each loop. We will first define
the values for the sidebar in our recipes_controller.rb file:
app/controllers/recipes_controller.rb
 before_action :set_values

  private
    def set_values
      @food_preferences = FoodPreference.all 
      @food_types = FoodType.all 
      @cuisines = Cuisine.all
    end
On page 33, Step 9,

The code is:

<%= link_to "Logout", destroy_user_session_path%>

It should be: 
<%= link_to "Logout", destroy_user_session_path, method: :delete %>
On page 20, point 11 , inside the code, the code is now showing as:
curry = recipes(:curry)
It should be:
curry = login(:curry)

On page 27, step 2,

The code is:

:~/curry-nation$ rails g scaffold recipe title:string cooking_time:string difficulty_level:string food_type_id:integer food_preference_id:integer
cuisine_id:integer ingredients:text procedure:text

 

It should be:

:~/curry-nation$ rails g scaffold recipe title:string cooking_time:string difficulty_level:string food_type_id:integer food_preference_id:integer
cuisine_id:integer ingredients:text procedure:text

On Page 29 in the Objective complete - mini debriefing section,

The following sentence is now showing as:

We also saw that we can define arrays and call them directly from our model
class like we did in the case of food type, food preferences, and cuisines."


It should be:


We also saw that we can define arrays and call them directly from our model
class like we did in the case of difficulty level.

On Page 39, in Hotshot challenges

The following sentence is now showing as:

Create another filter based on the level of difficulty, cuisine, food type,
and food preferences.

It should be:

Create another filter based on the level of difficulty similar to cuisine, food type,
and food preferences.

 

On Page 34,

 

Instead of anjlab-bootstrap-rails gem

 

Please use:

 

bootstrap-sass  https://github.com/twbs/bootstrap-sass

 

On page 47, step 2,        Errata type | Code
The second point is now showing as:
We will customize these events using the strftimefunction available in Ruby for 
converting the date to a more human-readable format in the following manner:
Config/locales/en.yml
en:
  time:
    formats:
       date_format: "%m/%d/%Y"
app/views/index.html.erb
<%= l event.start_date, :format => :date_format %>
<%= l event.start_time, :format => :date_format %>
It should be:
We will customize these events using i18n date format available in Rails in order to
convert the date to a more human-readable format:
config/locales/en.yml
en:
  time:
     formats:
         date_format: "%m/%d/%Y"
app/views/events/index.html.erb
<%= l event.start_date, :format => :date_format %>
<%= l event.end_date, :format => :date_format %>

On page 51, step 5,     Errata type | Code

 

The code in the fifth point is now showing as:

 

1.9.3-p327 :001 > User.find_each(&:save)

User Load (0.4ms) SELECT `users`.* FROM `users` ORDER BY 

`users`.`id` ASC LIMIT 1000

(0.2ms) BEGIN

(0.3ms) COMMIT

=> nil 

 

 

It should be:

 

Loading development environment (Rails 4.1.0.beta1)

2.1.1 :001 > Event.find_each(&:save)

  Event Load (0.6ms)  SELECT  `events`.* FROM `events`   ORDER BY `events`.`id` ASC LIMIT 1000

 => nil

Errata type: Graphics |page: 29

This is the updated image on page 29.

Errata type: Technical |page: 27

Replace this "We can now see what we have already created. In order to see what we have
created so far, let's fire up our server and see what we just created by navigating
to localhost:3000"

with

"We can now see what we have already created. In order to see what we have
created so far, let's fire up our server and see what we just created by navigating
to localhost:3000/recipes/new"

Page no: 54 | Errata type: Code

In step no 8, the following code is now showing as:


params.require(:event).permit(:title, :start_date,
:start_time, :location, :agenda, :address,
:organizer_id, :all_tags)


It should be:


params.require(:event).permit(:title, :start_date,
:end_date, :location, :agenda, :address,
:organizer_id, :all_tags)



Page no: 55 | Errata type: Code

In step no 9, the following code is now showing as:

app/views/events/_form.html.erb
<div class="field">
all_tags
<%= f.label :all_tags, "List All Tags, separate each tag by a comma" %><br />
<%= f.text_field :all_tags %>
</div>


It should be:


app/views/events/_form.html.erb
<div class="field">
<%= f.label :all_tags, "List All Tags, separate each tag by a comma" %><br />
<%= f.text_field :all_tags %>
</div>




Page no: 61 | Errata type: Code

In Step 1, the following code is now showing as:

gravatar_id = Digest::MD5::hexdigest(user.email).downcase



It should be:


gravatar_id = Digest::MD5::hexdigest(user.email.downcase)




Page no: 59 | Errata type: Code

In step 7, the following code is now showing as:

app/assets/tags.css



It should be:



app/assets/stylesheets/tags.css





Page no: 57 | Errata type: Code

In step 2, the following code is now showing as:

<%= event.all_tags.map { |t| link_to t, tag_path(t) }.join(', ') %>


It should be :


<%=raw event.tags.map(&:name).map { |t| link_to t, tag_path(t) }.join(', ') %><br/><br/>




Page no: 54 | Errata type: Technical

In step 8, the following sentence is now showing as:

These tags should be mounted to a model like an attribute of it. Rails 4 has a new
way to set up whitelisted attributes. Strong parameters are no longer supported
and attribute_accessor methods.

It should be:

Strong parameters support is added in Rails 4. It replaces the older method of defining attribute_accessor methods in the model.




Page no: 56 | Errata type: Grammar


"Depreciation of strong parameters is a major change in Rails 4."

Should be :

"Introduction of strong parameters is a major change in Rails 4."

Sample chapters

You can view our sample chapters and prefaces of this title on PacktLib or download sample chapters in PDF format.

Frequently bought together

Rails 4 Application Development HOTSHOT +    Microsoft Hyper-V Cluster Design =
50% Off
the second eBook
Price for both: $45.60

Buy both these recommended eBooks together and get 50% off the cheapest eBook.

What you will learn from this book

  • Learn about new syntaxes and semantics introduced in Rails 4 and their practical usage
  • Discover new ways to use the components and gems from previous versions of Rails
  • Set up full-text search, endless scroll, and modal boxes
  • Create mountable engines and make the code reusable
  • Make multiple APIs (such as Google Maps and Twitter) work with each other
  • Create API-only applications to serve as a backend for mobile applications
  • Understand the basics of the new testing framework in Rails 4
  • Create a video sharing website using Rails 4 along with HTML5 and CSS3 concepts

In Detail

Rails is a rapidly moving, open source, web development framework, and keeping up to speed with it is a big task. You might have already built applications using it, but there have been significant changes in the syntax and semantic of the Rails framework in the latest upgrade.

Rails 4 Application Development Hotshot shows you how to build the most popular types of applications using Rails 4, and highlights new ways to do things. The book also closely follows lots of the best practices, gems, and popular solutions already known to the community, and tracks the changes in these. This book brings new ideas to refactor and restructure code to make it perform better in production, and enables you to write production-ready code.

Approach

Attractive practical projects to polish your application building skills, through a straightforward, highly focused and interesting approach towards application development.

Who this book is for

If you are a developer who is already familiar with the basics of the Rails framework and have previously worked with Rails 3.2 or earlier, then this is the ideal book for you. It is assumed that you have some prior experience with the development of applications. This book will help you to upgrade your existing knowledge and also ensure its applicability. You will be expected to setup Rails, MySQL / PostgreSQL, Mongodb and required dependencies themselves.

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software