Skip to content
Chandan Kumar

Dynamic Programming: Screw your class on the fly

programming, ruby1 min read

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 {% highlight ruby %} class Region < ActiveResource::Base

1end

{% endhighlight %}

Sinatra Controller {% highlight ruby %} get :list do content_type :json Region.find(:all, :params => params).to_json end

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

{% endhighlight %}

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!

Comments

Copyleft. WTH
Theme by LekoArts