Rails : acting weird : why layout is rendered when format.js

I don’t know why I am getting this issue. I have set remote: true in link_to helper method in view. and the controller is supposed to look like

class ProfilesController < ApplicationController
  def index

  def profile_setting
    respond_to do |format|

I have the file views/profiles/profile_setting.js.erb. I can even pry into the .js template using binding.pry [using pry-rails gem]. It renders the template but also renders layout i.e. layouts/application.html.erbContinue reading

Ruby && Rails : FreshDesk : SSO[Single Sign On]

Here is how SSO/ Remote Authentication works:

  • A user (agent/customer) wants to remotely log into your support portal.
  • You redirect the user to a remote login page you set up.
  • The user enters his login credentials and you validate him.
  • You perform an HMAC-MD5 hash on his login details (name, secret key, email and time stamp in that order) using the secret key Freshdesk shares with you and generate a hash.
  • You send Freshdesk the encrypted value and the user’s login details this way:
  • Freshdesk performs the same HMAC-MD5 hash on his login details using the secret key and checks if the resulting hash matches the hash you sent.
  • If they match, Freshdesk knows that the user has been validated by you already and grants access to your portal.


First Generate MD5 Hash from

# Gets MD5 HASH from some unique keys to be passed to FreshDesk
# @return [String] A Digest
def gen_hash_from_params_hash
  digest = OpenSSL::Digest.new('MD5')
  OpenSSL::HMAC.hexdigest(digest, sso_secret, url_params)


# Gets URL params in GET format
# @return [String]
# Note: This method is no more supported from May 2016
def url_params
# Gets URL params in GET format
# @return [String]
def url_params
 # Gets time in UTC for FreshDesk to compare with # @return [Time] def time_in_utc Time.now.getutc.to_i.to_s end

And finally you can generate the SSO URL for your client

# Gets URL along with params required to authenticate to FreshDesk
# Its a instance method
# @return [String]
def get_redirection_url
  sso_domain + "/login/sso?name=" + username +
      "&email=" + email +
      "&timestamp=" + time_in_utc +
      "&hash=" + gen_hash_from_params_hash +
      "&redirect_to=" + redirect_url +
      "&company=" + get_company



Useful links



Heroku : Update Cedar

The legacy Cedar-10 stack has been deprecated and reached its end-of-life on November 4, 2015. Applications may continue running, however you will not be able to push to your application without upgrading to Cedar-14 first.

Due to changes in the glibc library on Cedar-14, apps may see different memory consumption behavior on that stack. See the Performance Differences section for details. Continue reading

Reporting in Rails : Report generation : Downloadable in any Format | PDF | CSV | XLS

Working on report generation is a time consuming task yet very necessary for any software projects. End of the day every business owner needs to see where their business stands or see ongoing activity in the system. Reports need list of records and Graphs/Charts to show the big-picture at a glance.

 With Rails Admin

If you are using RailsAdmin for managing you web-application from backend, you get reports for your data out of the box. In addition you can edit/update in no time with ease. You will not have charts and graph at that instant though.

How can I get Charts?

Continue reading

How to get charge id after creating a subscription using Stripe?

Well there is no straight-forward way to do this. There is however a hack to get charge_id for thatsubscription with out waiting for invoice.payment_succeeded callback.

This how I did in Ruby, you can treat this as a pseudo code. May be you can do this using PHP APIs

  # Lets not retrieve all the invoices
  #  use filter
  lower_limit_date = DateTime.strptime(that_subscription.start.to_s, '%s') - 1.hour
  upper_limit_date = 2.hours.from_now

  list_object_of_all_invoices_in_range = Stripe::Invoice.all(
          customer: customer_id,
          date: {
              gt: lower_limit_date.to_i, # Start TimeStamp
              lt: upper_limit_date.to_i # End TimeStamp

  particular_invoice = list_object_of_all_invoices_in_range.data.
      keep_if { |s| s[:subscription] == that_subscription.id }.first

  stripe_charge_id = particular_invoice.charge # gives charge_id

See structure of ListObject for Invoices