Passing commandline parameter (arguments) to ruby file using optparser

Ruby file accepts from command prompt in the form of array.Passing parametersruby input.rb TOI DH TimesNewAccessing parameters # input.rb p ARGV # => ["TOI", "DH", "TimesNew"] p ARGV[0] # => "TOI" p ARGV[1] # => "DH"Optparser : parses commandline options in more effective way using OptParser class.and we can access options as hashed parameters.Passing parametersruby … Continue reading Passing commandline parameter (arguments) to ruby file using optparser

How to get all associted models of rails model

I have Site Model and i wanted to find all associated models of Site model which are having belongs_to relationship.After doing lot headache, here is the solution i foundhas_many models of Site Model Site.reflect_on_all_associations.map{|mac| mac.class_name if mac.macro==:has_many}.compact=> ["Layout", "User", "SubmenuLink", "Snippet", "Asset"]belongs_to model of Site ModelSite.reflect_on_all_associations.map{|mac| mac.class_name if mac.macro==:belongs_to}.compact=> ["User", "Page", "User"]To get all associationsSite.reflect_on_all_associations.map{|mac| … Continue reading How to get all associted models of rails model

bundling gems in rails application

Gem Bundling is basically used to maintain all required gems at your application level.It downloads necessary gems and maintain it under "/vender/gems" directory.Its very easy to use gem bundle.1. Insatll gemcutter gem ( Its gem hosting )gem install gemcutter2. Install bundler ( Its a tool that manages gem dependencies for your ruby application. )gem install bundler3. … Continue reading bundling gems in rails application