Thursday, 22 August 2013

Exception Notifier Plugin for Rails



ROR version

        Ruby=>3.2.13
        Rails=>1.9.3
   

Gemfile

    Add  below gems into your Gemfile

            gem "mail"
            gem "exception_notification",
                     :git => "git://github.com/rails/exception_notification.git",
                       :require => "exception_notifier"


if you going to run application in development mode 

                 development.rb

                        config.action_mailer.raise_delivery_errors = true(default false so you must chang true)

                    add below two lines

                         config.action_mailer.delivery_method = :smtp
                         config.action_mailer.perform_deliveries = true

                   application.rb(config/)

                               add below configuration into application.rb

                            config.action_mailer.smtp_settings = {
                                             :address              => "smtp.gmail.com",
                                             :port                 => 587,
                                             :domain               => 'test.com',
                                             :user_name            => 'notifier@gmail.com',
                                             :password             => 'xxxxxxx',
                                             :authentication       => :plain,
                                            :enable_starttls_auto => true  }
 

                         config.middleware.use ExceptionNotifier,
                                        :email_prefix => "[myAppliction Error Report]  ",
                                        :sender_address => %{"notifier" <notifier@gmail.com>},
                                        :exception_recipients => %w{gowthaman@gmail.com}
                           end
       
     if you going to run application in production mode 
    
                   production.rb

                    add below three lines

                         config.action_mailer.raise_delivery_errors = true
                         config.action_mailer.delivery_method = :smtp
                         config.action_mailer.perform_deliveries = true

                  and add below configuration into production.rb

                            config.action_mailer.smtp_settings = {
                                             :address              => "smtp.gmail.com",
                                             :port                 => 587,
                                             :domain               => 'test.com',
                                             :user_name            => 'notifier@gmail.com',
                                             :password             => 'xxxxxxx',
                                             :authentication       => :plain,
                                            :enable_starttls_auto => true  }
 

                         config.middleware.use ExceptionNotifier,
                                        :email_prefix => "[myAppliction Error Report]  ",
                                        :sender_address => %{"notifier" <notifier@gmail.com>},
                                        :exception_recipients => %w{gowthaman@gmail.com}
                           end



If you want to send notifications from a background process like DelayedJob, you should use the notify_exception method like this:

begin
  some code...
rescue => e
 ExceptionNotifier.notify_exception(e)
          end

Refer: gem exception_notification

Friday, 24 May 2013

How to clone a single branch in git?


How to clone a single branch in git?
I have a local git repository called 'skeleton' that I use for storing project skeletons. It has a few branches, for different kinds of projects:
casey@agave [~/Projects/skeleton] git branch
* master
  rails
  c
  c++



git clone user@git-server:project_name.git -b branch_name /some/folder

pdfkit command failed: “/usr/bin/wkhtmltopdf” “--page-size” “Letter” “… ”--quiet“ ”-“ ”-"

Error:

  Create PDF Error :
 
  RuntimeError (command failed: "/home/ubuntu/.rvm/gems/ruby-1.9.3-p392@xxx/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-right" "0.75in" "--margin-bottom" "0.75in" "--margin-left" "0.75in" "--encoding" "UTF-8" "--quiet" "-" "-")

Solution:


 (1)  first, installing dependencies
 $sudo aptitude install openssl build-essential xorg libssl-dev

(2) for 64bits OS Run one by one following commands.

$sudo wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$sudo tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
$sudo mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
$sudo chmod +x /usr/local/bin/wkhtmltopdf

Finally Go to your rails app/config/initializer Folder and create new file pdfkit.rb and paste following code in it.

PDFKit.configure do |config|
   config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf' if Rails.env.production?
end


 I refer generating-pdfs-in-rails-with-pdfkit-and-deploying-to-a-server link

Monday, 20 May 2013

How to resolve jcode (LoadError) with contacts gem in rails 3? change line 21 to:




Ruby >= 1.9 doesn't have jcode, a module to handle japanese (EUC/SJIS) strings, as it supports unicode natively.

So you will need to add: require 'jcode' if RUBY_VERSION < '1.9' to your gdata gem found under your .rvm directory somewhere similar to this:

/home/.rvm/gems/ruby-1.9.2-p0@your_gemset_name/gems/gdata-1.1.1/lib/gdata.rb
change line 21 to:

if RUBY_VERSION < '1.9'  require 'jcode'  $KCODE = 'UTF8'end

Sunday, 5 May 2013

How to clone a single branch in git?branch_name



I have a local git repository. has a few branches, for different kinds of projects:

open terminal

   # cd  /home/project path
         
                git branch
             * master
                rails
                dev
 


Solution:

           git clone user@git-server:project_name.git  -b branch_name      /some/folder

Monday, 29 April 2013

how to run a scheduler.rake file in rails?



If you don't see your command in the response list then it is not well formed or just does not have description. So you need to investigate your rake file. Rake tasks files have similar structure, like:

namespace :some_task do

  task :do_some_work => :environment do
    # Code goes here
  end

  desc 'Do some other work'
  task :do_something => :environment do
    # Code goes here
  end

end

#first task
rake some_task:do_some_work

#second task
rake some_task:do_something

Sometimes there could be no namespace and then tasks could be executed just using rake command and name of the task as first argument.

Tuesday, 23 April 2013

ruby installation is missing psych (for yaml output).



Problem it seems your ruby installation is missing psyh (for yaml output).centos solution curl -O http://www6.atomicorp.com/channels/atomic/centos/6/x86_64/RPMS/atomic-release-1.0-14.el6.art.noarch.rpm sudo rpm -Uvh atomic-release-1.0-14.el6.art.noarch.rpm sudo yum install libyaml-devel rvm reinstall 1.9.3-p194