Home

How to solve the error: no decode delegate for this image format

Today I am trying to use CarrierWave to convert image’s format, from png to jpg, then I MiniMagick::Invalid error. When I use command line tool to detect the format, it shows “identify: no decode delegate for this image format `xxx.png’ @ error/constitute.c/ReadImage/544.” After I googled a litte while, I found “convert -list configure” command could show all image processing delegate, like “DELEGATES bzlib jpeg jp2 lcms tiff xml zlib”, then it miss PNG, so after I use “brew tap homebrew/versions/libpng12”, it works then.


Capistrano with bundler

Today I suddenly got an error on website, it said there is one gem doesn’t been installed somehow. but when I ssh to server, use bundle install, found both server was installed all gems that application needs.

Finally I got the reason, the passenger doesn’t loading the gems correctly from bundler, so you have to run bundle install like this way bundle install --deployment. This installation will move all gems to “vendor/bundle”, which will freeze all version of gems into the project.

For capistrano, add below lines into deploy.rb file:

  set :bundle_roles, [:app]
  require 'bundler/capistrano'

New xcode uncomfortable things

Haven’t been working on latest version of Xcode so far, today I tried to use it found many things are different.

  1. You have to add Files to “Compile Sources” List in Build Phases.

  2. You have to add “-fno-objc-arc” for files which no need support ARC.

  3. You have to add the “xib” or “nib” to the “Compile Sources” also.

  4. You should not drag .h files into “Compile Sources”.

  5. Font or some images you have to add them into “Copy Bundle Resources”.


Problem with carrierwave when you have two servers

Today I got a very strange problem when I using carrierwave, When I upload some pictures and the form validator told me some fields need to be filled, then I fill them and submit the form again, the uploaded file supposed to be cached, but it randomly told me some file supposed to be cached are missing.

After investigate a little bit I found I have 2 servers, and the cache file only stored on one of the server, so when request goes to another server which doesn’t has cache file, it will report no file uploaded.

For solving this, I just mount one directly to another server, make the cache directly the same.

Steps:

  1. On NFS server side: sudo apt-get install nfs-server portmap nfs-common

  2. On NFS client side: sudo apt-get install nfs-client nfs-common

  3. Add below line to /etc/exports /path_to_tmp_folder/tmp client_server_ip(rw,sync,no_subtree_check,no_root_squash)

  4. Restart service exportfs -ra /etc/init.d/nfs-kernel-server restart /etc/init.d/portmap restart

  5. Mount the directory on another server: sudo mount -o soft,intr,rsize=16384,wsize=16384 server_ip:/path_to_tmp_folder/tmp /local_path_to_empty_tmp_folder/tmp

  6. Add below line to /etc/fstab, this is for auto mount when server reboot: server_ip:/path_to_tmp/tmp /local_empty_folder/tmp nfs rsize=16384,wsize=16384,rw,auto,nolock


use ActiveSupport::Configurable to store config options

class Employee
  include ActiveSupport::Configurable
  config_accessor :research_lab_entry, :paid_leave
  
  # The config options are now also available as: 
  # employee.research_lab_entry
  # employee.paid_leave
end
# Set the config option at the class level
Employee.config.paid_leave = 5

# Create a new object and check the value
employee = Employee.new
employee.config.paid_leave # => 5

# Set a new value at the object-level
employee.config.paid_leave = 3

# Now check the value at the class level
Employee.config.paid_leave # => 3