Skip to content

Instantly share code, notes, and snippets.

@MollsReis
Created April 11, 2012 15:33
Show Gist options
  • Save MollsReis/2360068 to your computer and use it in GitHub Desktop.
Save MollsReis/2360068 to your computer and use it in GitHub Desktop.
Jimson and Sinatra playing together
require 'sinatra'
require 'jimson'
class Api
extend Jimson::Handler
def get_data
{'foo' => 'bar'}
end
end
get '/' do
haml :index
end
post '/json-rpc' do
Jimson::Server.new(Api.new).call(request.env)
end
__END__
@@ index
%html
%head
%title Hobo
%script{ :type => 'text/javascript', :src => '//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' }
:javascript
$(document).ready(function(){
$('#get-data').click(function(){
$.post(
'/json-rpc',
JSON.stringify({method: 'get_data', id: 1, jsonrpc: '2.0'}),
function(data){ $('#data').html(data.result.foo); },
'json'
);
});
});
%body
%p
%input{ :type => 'button', :id => 'get-data', :value => 'Get Data' }
#data No data yet!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment