Showing posts with label date diffrence in ruby. Show all posts
Showing posts with label date diffrence in ruby. Show all posts

Saturday, November 19, 2011

Gmail SMTP setting in rails3

SMTP setting for rails3and put new gmail.rb then run.

require 'rubygems'
require 'action_mailer'
require 'tlsmail'

  Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
  ActionMailer::Base.delivery_method = :smtp
  ActionMailer::Base.perform_deliveries = true
  ActionMailer::Base.default_charset = "utf-8"
  ActionMailer::Base.raise_delivery_errors = true


ActionMailer::Base.smtp_settings = {
  :enable_starttls_auto => true,
  :address => "smtp.gmail.com",
  :port => 587,
  :domain => "domainname",
  :authentication => :plain,
  :user_name => "notifications@domainname",
  :password => "password"
}


class Emailer < ActionMailer::Base
  def test_email()
    subject    "Test message"
    from       "Test mail"
    recipients 'recipients@domainname.com'
    body        "Test mail for gmail SMTP setting"
  end
end

Emailer.deliver_test_email()

Wednesday, February 10, 2010

Calculating the Number of Days Between Two Dates in ruby on rails



def room_expiry_date_in_days(room)
a=room.expiry_date.strftime("%Y-%m-%d")
b=room.created_at.strftime("%Y-%m-%d")
a=Date.parse(a)
b=Date.parse(b)
days=(a-b).to_i
return  "#{pluralize(days, 'day',"days")} left"
end