Flowdock

Notes posted by harm

RSS feed
June 8, 2009 - (>= v2.2.1)
5 thanks

This is ON by default in :has_many

When defining a has_many relationship this behaviour is on by default. See has_many documentation, look for the :validate flag.

January 9, 2009
3 thanks

Adding params to generated url

Whenever you want to append custom parameters to a to be generated url it might be necessary to stop url_for from escaping.

url_for(:action => 'some_action', :custom1 => 'some_value', :custom2 => 'some_value', :escape => false)

If the escape => false option is not passed the generated url contains & instead of the correct &-sign.

November 7, 2008
2 thanks

Parsing YAML from a POST request

When building a REST server which should accept YAML there are several things to take into consideration.

First of the client should tell the server what type of data it is going to send. This is done via the Content-Type header (which is NOT only a response header as opposed to what the RESTful Web Services book from O’Reilly made us believe).

Second the server application should know how handle the body of the POST request. Placing the following line in your environment.rb:

ActionController::Base.param_parsers[Mime::YAML] = :yaml

This registers the YAML parser. Smooth sailing from here on!

November 5, 2008
2 thanks

Rendering YAML

When you want to render XML or YAML you can use

render :xml, some_object.to_xml 

or

render :json, some_object.to_json

However there is no equivalent for YAML. What you can do is render just plain text with a correct content-type:

render :text => some_object.to_yaml, :content_type => 'text/yaml'

The content_type is debatable but this seems to be the most standard.