#meetrailslove – May 2012
Like every month there are some awesome events coming up. Here are a few – and at some you can #meetrailslove:
- Adcloud TechTalk (25.04.): This Wednesday AdCloud are hosting their first TechTalk. The first talk will be about Chaplin – a JavaScript Application Architecture with Backbone.js. For more information check out http://dev.adcloud.com/blog/2012/04/16/chaplin/. This is a really good opportunity for anyone interested in frontend technology to learn about one of the most exciting new JavaScript projects. More information on Chaplin can be found on http://9elements.com/io/
- Kölsch.rb (25.04.): Like every month the Cologne Ruby User Group meets for some very interesting discussions. E.g. AvocadoDB and embedded Ruby with “mruby”, “Ruby on R with RSRuby” or some testing small talk with Ede. This week we’re meeting at Coworking Cologne Gasmotorenfabrik. If you have any point of contact with Ruby development this event should be required for you. For more information check out http://hcking.de/events/40/single_events/570.
- ADVANCE HACKATHON (27.04.-29.04.): A meetup for hackers and thinkers – imagine you are sitting together with the most talented web & app developers and designers for kicking off your own or others’ projects, refine or complete code collaboratively, or just experiment with others. This is the purpose of the hackathon and if you have any interest in the web at all you will find no better place to meet interesting people and see a lot of cool projects. For more information check out http://hackathon.advance-conference.com/en/. Unfortunately this is event is already sold out.
- Webmontag (07.05.): Webmonday is an informal, non-commercial, and completely community-driven event that aims to connect the people who are shaping the future of the internet. As usual we’re discussing interesting web driven topics, hacking ideas etc. Check out: http://www.webmontag.de/location/koeln/2012-05-07
- UX-CGN (15.05.): UX-CGN is a new format discussing different topics about user experience. If you’re interested in frontend, frontend development and usability, visit this user group and meet people that speak your language. http://uxcgn.org/
- SIGINT (18.05.-20.05.): SIGINT is a conference on discourses in the digital age. It addresses socio-political demands for participation and change, utopias, hacktivism, as well as the creative breaking of norms. For more information check out http://sigint.ccc.de/Main_Page.
- Clash of Realities Conference! – 4th international Computer Game Conference (23.05.- 25.05.): The international game developer scene comes to Cologne to meet for a three day conference organized by the Department of Media Studies and Media Education and the Cologne Game Lab in cooperation with Electronic Arts. If you wanna get into the world of game development this is your chance. For more information check out http://www.clashofrealities.org/.
- DevHouseFriday Chillout (25.05.): we’ve moved the meetup because of the ADVANCE HACKATHON. The next DevHouse Friday is happening @ Pixum – “Wir machen den DevHouse Friday Chillout zum Erlebnis” and is a great chance go meet a lot of interesting people around the Cologne web scene. For more information check out http://devhousefriday.org/networks/events/show_event.52535.
- Bastelnachmittag Every Friday: the Dingfabrik meets in their rooms for Bastelnachmittag. Just play around with your arduino or do some origami – everyone can have some fun! Date: Friday 4th of May. For more information check out: http://hcking.de/events/84-dingfabrik-bastelnachmittag
On the international scene the DLD Moscow is happening from 27th – 29th May, 2012. Check out Moscow calling DLD.
For more events check out this and this event calendars.
We wish you a very eventful May!
Help You need somebody; Help not just anybody!
Here at Railslove, we love building web applications. But aside from our core business, we also help other startups understand how the web works and what it means to run a web business — in Hamburg, Berlin, Cologne. And since experienced Ruby on Rails developers are increasingly hard to find, we’ve started to offer apprenticeships, too.
One of our new partners is DailyDeal. We’ve done some beginners and advanced courses in Rails covering stuff like testing, building APIs, advanced JavaScript coding and general design and programming patterns in Ruby on Rails, etc.
Oliver Hepfner, Director Software Engineering of DailyDeal:
The training Railslove provided under the direction of Georg Leciejewski helped us understand advanced programming patterns in Ruby on Rails. Our developers were excited to get a hands-on introduction into Ruby on Rails.
Next month, we will launch a few more courses with DailyDeal and with other companies, like Adcloud GmbH in Germany. If you are interested in learning more, please contact Ralph and Georg: ralph AT railslove.com & gl AT salesking.eu & team AT railslove.com
JSON Schema Baby
Building an application programming interface is not easy. Designing an API is more complex than just writing code. For a few projects we tried out different approaches to implement an API in Ruby on Rails. There are two main ways to make your resources accessible:
- using the standard to_json renderer built into Rails
- building your own views
Using standard renderer provided by Rails
In Rails 2.0 you have the possibility to using the respond_to block to expose your resource in whatever format you rewuire (xml, json, html). E.g.:
The same is possible in Rails 3.0 but a little bit easier:
In these examples you can define the representation of your resource by defining the format you want the resource to be represented in. But in most cases you don’t want to expose every attribute of your resource. To achieve this, you could use Rails’ as_json method to create a custom JSON structure of your resource. E.g:
As Jonathan Julian mentioned in his blog post, call as_json directly or override it in your model to customize your representation of your resource. Sounds easy so far. Summarizing this approach we can say:
- It is understandable and quite easy to use
- You can easily customize the representation of your resources via the as_json method
But the way how this approach is realized is not the best in my opinion, because it too much correlated with the models when we talking only about a “representation”. That’s why I like the second approch – building your own views.
Customize it baby
What does it exactly mean? Instead of just overriding the as_json method in your model, build a template that exposes your API. The easiest way is, e.g., to use RABL – Ruby API Templating Language.
As in the example before you define within your controller structure WHICH resources are being exposed, like:
And within your RABL-Template now you can define HOW your resources should look:
What happened here is that the representation of the resource is properly split from the resource using templates, like using .html-templates that belongs to your views. Thats great. You’re very flexible to define how the respresentation should looks like without overriding some methods. The resource is exposed ‘as it is’ but the template takes the response of what representation exactly the API users should get. In general, that seems to be the right approach; and it really is, but for me it isn’t going far enough. What I like to see is an even looser representation.
Here comes JSON-Schema
Now we’re going a step further and completely split our resource from the representation. Based on JSON-Schema (http://json-schema.org/) we’re going to define one that is responsible how our resource is being represented. With this approach, it is also possible to define our yourself in which way you want to interpret the schema within your code. And it’s fully decorrelated if you want to.
If found a very good approach for using the JSON-Schema for an API representation (sk_api_schema – https://github.com/salesking/sk_api_schema) – a Ruby library that defines the schema which takes care of the representation of their API resources.
How does it work? Your controllers are almost the same. E.g.:
The only small difference is the object_as_json method, which is provided by your own schema library. This method takes the properties defined in the schema and looks them up on the object in question.
Within your schema for a single resource looks like this:
As you can see, the schema described everything:
- The resource itself – here a user
- Its properties – the attributes of this resource
- Links belonging to this resource – These describe some nested resources which belong to this resource and you can also define search parameters here
And there’s even one more big advantage: publishing your JSON-Schema library gives your API users a good and clean documentation of your interface. You don’t have to describe it anymore. Moreover, it could be possible to generate a nicer representation from your documentation. You can see an example of thishere: http://sk-api-browser.heroku.com/. This API browser reads the JSON-Schema here and generates a nice overview of the API.
Summary
What I tried to describe here were some facts about how to implement an API with Ruby on Rails but more about how to split the resource itself from the representation in your webservice. For this you can use internal methods responsible for representing your resource, or create your own templates with defined libraries like RABL. Using JSON schema for the representation of your API is the most loosely coupled approach. With JSON schema you’re don’t care about the resource’s representation within your code but reather within your schema. It’s a description of whatever you want to expose to your clients.
Resources
- A JSON schema browser
- SalesKing API schema
- JSON schema
- Set up RABL for Ruby on Rails
- Using RABL in Rails JSON Web API
- RABL
- RABL, The Ruby API Templating Language
- Rails to_json or as_json?
Nerds/NerdPursuit
For nerds, from nerds.
We’ve presented this projects a few times at Webmontag Köln and DevHouse Friday Chillout @ Papaya and Millepondo. Now we have about 100 Questions in 14 different Topics (algorithms/ bash/ couchdb/ css/ culture/ flash/ grafix/ html/ http/ javascript/ php/ rails/ regex/ ruby/) . But we’re still missing many.
Beside creating new questions we’re working on an offline game – and hey 9elements brought to us – a real time nerd pursuit game – fuck yeah! (will be linked soon).
Participate and send us as much pull requests as you can!
Introducing Bieber.ly

Last night at The Riot HQ we had a hack night. It was an awesome night of beer, pizza and hacking.
From the hacking emerged the most awesome URL shortener…Bieber.ly. It even got on Techcrunch!
Big thanks to @elliottkember, @dizzup, @juliancheal, @philsturgeon and of course @theriothq for holding such a great night.