Book Image

Rails 4 Application Development HOTSHOT

By : Saurabh Bhatia
Book Image

Rails 4 Application Development HOTSHOT

By: Saurabh Bhatia

Overview of this book

<p>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.</p> <p>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.</p>
Table of Contents (17 chapters)
Rails 4 Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating file uploads and image resizing


As seen in previous projects, we will mockup our application page and create a sample layout similar to Pinterest as follows:

In this section, we will use the carrierwave gem to upload images and resize them into different sizes in order to display them on different pages. For example, we will display thumbnails on listing pages and larger images on individual pages.

Prepare for lift off

Before we start off with creating the upload methods, we will create two models and controllers for board and pin as follows:

$ rails g scaffold board title:string description:text
$rails g scaffold pin name:string image:string board_id:integer

We will create an association between pin and board as follows:

models/pin.rb
  belongs_to :board
models/board.rb
  has_many :pins

A user model is generated using the devise gem. We will also create an association between user and boards:

models/board.rb
  belongs_to :user
models/user.rb
  has_many :boards

We will also use friendly_id...