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…
by sandipransing
While developing rails application we often come across situation where you wanted different rails models connecting different tables of different databases.
Example: We are having ndnc model holding ndnc records associated with database ndnc.
Lets create ConnectionBase model that will connect to other databse 'ndnc' and that will be extended from ActiveRecordBase and put that inside library files
vi lib/connection_base.rb
class ConnectionBase < ActiveRecord::Base
establish_connection(
:adapter => "postgresql",
:username=> "sandip",
:password => "2121",
:database => "ndnc"
)
end
Wherever you wanted to connect to other database i.e. ndnc you can extend that particular model with ConnectionBase
class Ndnc < ConnectionBase
# connects to ndnc table of ndnc database
end
Please make sure library files are loaded while server startup
# vi config/application.rb
config.autoload_paths += %W(#{config.root}/lib)
Done !
In cases where you want only one particular model connecting other database table, you can put connection setting itself in that model.
Read More…
by sandipransing
In order to get tata photon working on ubuntu machine you need to install following packages
1. usb-modeswitch-data
2. usb-modeswitch
Either you can download them from ubuntu site and install locally or install using apt manager
Download links
http://packages.debian.org/squeeze/usb-modeswitch-data
http://packages.debian.org/squeeze/usb-modeswitch
apt installation
sudo apt-get install usb-modeswitch-data usb-modeswitch usb-modeswitch
After successful installation,
1. Connect photon usb card
2. Execute following commands one after another.
sudo usb_modeswitch -c /etc/usb_modeswitch.d/12d1\:1446
wvdial
...and you should get connected via photon!
Read More…
by sandipransing
Edit nginx configuration and look for html block.
Inside html block add following line.
http {
include conf/mime.types;
default_type application/octet-stream;
client_max_body_size 10m;
....
}
In above configuration "application/octet-stream" supports any kind of file upload.
Read More…