Hello there! I am Chandan. I work at LiftOff as a software engineer. This page is cursor to ‘my ramblings’, occasional work, some source code etc. You can find me on following networks. Stackoverflow

I spent about an hour trying to figure out why Sinatra app was spinning off the track. Basically after the update call(put), Region model started to misbehave.

Active Resource Model
1
2
3
class Region <  ActiveResource::Base

end
Sinatra controller
1
2
3
4
5
6
7
8
9
10
    get :list do
      content_type :json
      Region.find(:all, :params => params).to_json
    end

    put :update do
      obj = JSON.parse request.body.read
      Region = Region.find(params[:id])
      Region.update_attributes(obj).to_json
    end

Do you see any problem in above code?

Well the problem lies with Region = Region.find(params[:id]). I redefined the class inadvertently. Yes, you can do that. Java fanboys I am not lying. Try Ruby, and welcome to the hell!

Snippet to use Redis as session store on Heroku with Moneta Gem. I have no idea why I did not had tried it out before, but looks pretty neat. Please leave a comment in case you have any opinion about the Gem itself.

Somewhere in config
1
2
3
4
5
6
7
8
9
# Set session store
if(ENV["RACK_ENV"] == 'development')
  # use localhost for development
  use Rack::Session::Moneta, store: :Redis
elsif(ENV["RACK_ENV"] == 'production')
  url = ENV["REDISTOGO_URL"]
  uri = URI.parse url
  use Rack::Session::Moneta, store: Moneta.new(:Redis, host: uri.host, port: uri.port, password: uri.password)
end

I had to post this as I wasted 3 hours trying to figure out how to get it working. BTW I got that sample config in Padrino app.rb and it works just

Leh was running in my head and I was running in Leh. Well, logging about this has been long pending

In July, 2013, I finally managed to get a glimpse of Kashmir. I have a page about it at Kashmir which of course isn’t complete. I hope someday I do post everything. BTW it’s follow up to Original Trip to Leh plan