Tuesday, November 22, 2011

rails 3.1.1 haml sass jquery coffee-rails devise twitter-bootstrap railroady heroku

by sandipransing 0 comments
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…

Monday, November 21, 2011

paperclip options aws-s3 config and rails

by sandipransing 0 comments
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…

Paperclip image upload via URL

by sandipransing 0 comments
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…

Wednesday, October 5, 2011

Legacy database connections in rails

by sandipransing 0 comments
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…

Monday, September 12, 2011

Print particular DIV inside HTML Page

by sandipransing 0 comments
Hiding Whole page content and displaying only particular div using css

<style media="print" type="text/css">
  @media print
  {
    body * { visibility: hidden; }
    #PrintDiv * { visibility: visible; }
    #PrintDiv { position: absolute; top: 40px; left: 30px; }
  }
</style>
Read More…

Wednesday, August 17, 2011

Migrating from svn to git

by sandipransing 0 comments
Migrating from svn to git
1. Install git-svn
sudo apt-get install git-svn 2. Clone svn repositoy git svn clone -s svn://server/project_myt/trunk proj To add svn users and git users mapping
Create author-file
#vi authorsfile sandip = sandipransing amit = amitk root = sandipransing
git svn --author-file=authorfile clone -s svn://server/project_myt/trunk proj 3. Add git repository url
cd proj git remote add git@github.com:USERNAME/project.git 4. Push repository to git
git push origin master To do svn pull for latest changes
git svn rebase
Read More…

Tuesday, July 5, 2011

How to get started with tata photon on ubuntu machine

by sandipransing 0 comments
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…

Friday, April 8, 2011

Setup Active Scaffold with rails 3 using jQuery

by sandipransing 0 comments
Create new rails project
rails new demo -d mysql Add active_scaffold gem to bundler
gem "active_scaffold_vho" Run bundle install command
bundle install Setup active scaffold to use jQuery
rails g active_scaffold_setup jquery create public/javascripts/rails_jquery.js create public/javascripts/jquery-ui-timepicker-addon.js create config/initializers/active_scaffold.rb insert app/views/layouts/application.html.erb insert config/locales/en.yml gsub app/views/layouts/application.html.erb Generate active scaffold for resource city & zone
rails g active_scaffold City name:string invoke active_record create db/migrate/20110408123206_create_cities.rb create app/models/city.rb invoke test_unit create test/unit/city_test.rb create test/fixtures/cities.yml route resources :cities do as_routes end invoke active_scaffold_controller create app/controllers/cities_controller.rb create app/helpers/cities_helper.rb invoke test_unit create test/functional/cities_controller_test.rb create app/views/cities rails g active_scaffold Zone name:string city:references invoke active_record create db/migrate/20110408123531_create_zones.rb create app/models/zone.rb invoke test_unit create test/unit/zone_test.rb create test/fixtures/zones.yml route resources :zones do as_routes end invoke active_scaffold_controller create app/controllers/zones_controller.rb create app/helpers/zones_helper.rb invoke test_unit create test/functional/zones_controller_test.rb create app/views/zones Add Associations
class City < ActiveRecord::Base end class Zone < ActiveRecord::Base belongs_to :city end class City < ActiveRecord::Base has_many :zones end Migrate database
rake db:create rake db:migrate == CreateCities: migrating =================================== -- create_table(:cities) -> 0.1411s == CreateCities: migrated (0.1413s) ========================== == CreateZones: migrating ==================================== -- create_table(:zones) -> 0.1507s == CreateZones: migrated (0.1510s) =========================== Start Server
rails s Visit Browser URL: http://localhost:3000/cities

Snap
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-ZMWWFqS0JIx8SO4fMtFcThe0WVs4Kd9pqOmQE9w6CwKU57B0UiWrs0ujwR6bEGKEJrq2wUHVlGIAo0a8_APhd625bYYtgtdfLBPqDvXz1ZEm2v49IG05tC_Bi4sOGt22DvIUn2TarD57/s1600/active_scaffold.png
Read More…

Thursday, April 7, 2011

Ghostype input Placeholder for search text fields using jQuery

by sandipransing 0 comments
Placeholder Demo

Ghostpe Demo

jQuery placeholder plugin can be used to display default text inside input text fields. HTML5 introduced type search fields with placeholder attribute support.
<input class="query" id="home-search" placeholder="Enter search text here" type="search" />
It should display default text "Enter search text here" inside text-field and when user tries to type something it disappears.
In order to achieve text marquee like effect to default text value with jQery use following jQuery code. It will type text character by character from left to right.
Same effect can be achieved by creating gif image of typing and placing it as background-image to text field with certain drawbacks like changing default text on the fly.
Place below code inside javascript tag in your html file
jQuery Code $(document).ready(function(){ var search = "#home-search"; var chars = $(search).attr('placeholder').split(''); $.each(chars, function(i, v){ setTimeout(function() { $(search).val((chars.slice(0, i+1).join(''))); }, 100*i); }); });
Got easy ??
Read More…

Thursday, March 31, 2011

Setting up nginx maximum upload size

by sandipransing 0 comments
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…

About The Author

Sandip is a ruby on rails developer based in pune and also a blogger at funonrails. Opensource contributor and working with Josh software Private Limited. for more info read Follow Sandip on Twitter for updates.

Connect With Me...

Github Projects

@sandipransing Twitter