by sandipransing
Install RVM first
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvminstaller)
rvm list known
# MRI Rubies
[ruby-]1.8.6-head
[ruby-]1.8.7[-p352]
[ruby-]1.9.3-head
ruby-head
# JRuby
jruby-1.2.0
jruby-head
# Rubinius
rbx-1.0.1
rbx-2.0.0pre
# Ruby Enterprise Edition
ree-1.8.6
ree-1.8.7-head
Install ruby 1.9.3
rvm install 1.9.3-head
rvm gemset create rails311
rvm use 1.9.3-head@rails311 --default
gem install rails -v3.1.1 --no-rdoc --no-ri
gem install heroku
gem install rb-readline
Create new rails project
rails new cdc -m http://railswizard.org/b22092a4358bbebb3a46.rb -J -T
Heroku Deployment Done
http://railsblank.heroku.com/ (production)
Local System nginx-passenger setup
gem install passenger
rvmsudo passenger-install-nginx-module
If you find pcre download error then make sure you libpcre-dev pkg
installed on your system otherwise install it and re-run
sudo apt-get install libpcre3-dev
Nginx Configuration
http {
passenger_root /home/sandip/.rvm/gems/ruby-1.9.3-head@rails311/gems/passenger-3.0.9;
passenger_ruby /home/sandip/.rvm/wrappers/ruby-1.9.3-head@rails311/ruby;
server {
listen 80;
server_name railsblank.local;
root /home/sandip/railsblank/public;
rails_env development;
passenger_enabled on;
}
git source code
git clone git://github.com/sandipransing/rails_blank.git
Read More…
by sandipransing
Stepwise guide to configure paperclip default options,
setting up aws-s3 storage in rails
Inside Gemfile
gem 'aws-s3', :require => 'aws/s3'
gem 'paperclip'
bundle install
Generate Print model to hold image
rails g model print image_file_name:string image_content_type:string image_file_size:string
rake db:migrate
Add s3 credentials to YML file
# config/s3.yml
access_key_id: DASDFG7KACNxIJdJXHPQ
secret_access_key: BnDrTnzCTX+R707wYEP/aCEqAsDFG7sgW
Add default paperclip attachment options to initializer
# Make sure to add host url inside config/environments
# HOSTNAME = 'http://lordganesha.com'
Paperclip::Attachment.default_options.merge!(
:storage => 's3',
:s3_credentials => YAML.load_file("#{Rails.root}/config/s3.yml"),
:path => ":class/:attachment/#{Rails.env}/:id/:style/:basename.:extension",
:default_url => "http://#{HOSTNAME}/images/paperclip/:class/:attachment/default.jpg",
:bucket => 'ganesha'
)
Add image attachment code to print model
# app/models/print.rb
class Print < ActiveRecord::Base
has_attached_file :image,
:styles => {:medium => ["400x400#", :jpg],
:thumb => ["100x100#", :jpg],
:slider => ["300x300#", :jpg]}
#validates_attachment_presence :image
validates_attachment_size :image, :less_than => 1.megabytes, :message => 'file size maximum 1 MB allowed'
validates_attachment_content_type :image, :content_type => ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/pjpeg', 'image/x-png']
end
Inside views
# inside new.html.haml
= form_for @print do
f.file_field :image
Read More…
by sandipransing
Upload image via paperclip via passing URL instead of file upload
# Consider Print instance with image as file attachment
class Print < ActiveRecord::Base
has_attached_file :image
def upload_image(url)
begin
io = open(URI.escape(url))
if io
def io.original_filename; base_uri.path.split('/').last; end
io.original_filename.blank? ? nil : io
p.image = io
end
p.save(false)
rescue Exception => e
logger.info "EXCEPTION# #{e.message}"
end
end
end
Text code from console
p = Print.new
url = "http://ocdevel.com/sites/ocdevel.com/files/images/rails.png"
p.upload_image(url)
Read More…