Reprocess all Paperclip Images in a model

We all make mistakes. It’s not hard to make a mistake on image sizes when configuring your Paperclip image sizes.

Simple changes like below would require you to resize all images on your Product Model

class Product < ActiveRecord::Base
has_attached_file :image, :styles => {
    :product_page => "400x400#",
  }
// changed to
class Product < ActiveRecord::Base
has_attached_file :image, :styles => {
    :product_page => "300x400#",
  }

What you can do is use the rails console and run the following:

$ rails c
1.9.3-p448 :001 > Product.all.each{|p| p.image.reprocess!}

Voila! All Product image attributes will be updated to the new size!

Basic YUM commands

Different linux flavors have different package managers. For CentOS and Redhat, yum is the default package manager. Here is a list of useful yum commands

1. yum update

You usually should be working with the latest version of your software. This is used for making a full system update.

yum update

2. yum list

This is used to make a list of available packages.

yum list

3. yum list installed

To list all packages that have already been installed

4. yum install

This is used to install packages for your system

yum install

5. yum search [packagename]

This is used to search packages available

yum search vsftpd

Rails 4 Image Assets in Stylesheets

Rails has been doing a fantastic job being at the top when it comes to new innovations. The latest is have default turbolinks which makes it faster for sites to reload. With turbolinks, only the body and title without having the need to reload your stylesheets. Isn’t it amazing?

Anyway, with new things comes new ways to doing things. In Rails 4, referencing assets in stylesheets are different now.

Using Image Assets

When adding an image background:

.div-with-image: {
  image-url('background.png');
}

Using Image Data

.div-with-image: {
  asset-data-url('background.png');
}

Generic Asset

.div-with-image: {
  asset-url('background.png', image);
}

How to Know your Ubuntu Version from the Command Line

This is a common question I have to know which version I am working with. Here are a few options you can do.

1. Get all the information

lsb_release -a
user@yourvps:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 12.04.3 LTS
Release:	12.04
Codename:	precise

2. Get the Codename

lsb_release -c
user@yourvps:~# lsb_release -c
Codename:	precise

3. Get the Description

lsb_release -d
user@yourvps:~# lsb_release -d
Description:	Ubuntu 12.04.3 LTS

4. Get the Release Number

lsb_release -r
user@yourvps:~# lsb_release -r
Release:	12.04