Tuesday, 17 September 2013

Sinatra - Calling a method based on the parameter passed

Sinatra - Calling a method based on the parameter passed

I have this specific route I want to implement in Sinatra:
post '/activate/:model/:id/?' do
model.activate stuff
basically what happens here is that I get the model name using
Module.const_get. I then call the activate method on the object. Now I
want to add a deactivate method, I can duplicate the code and just modify
it to be deactivate, but it's not very DRY-ish. I should probably use a
Regex, right? How do I "dynamically call a method" (aka call deactivate or
activate depending on the route?

No comments:

Post a Comment