Created
September 18, 2012 05:21
-
-
Save mccun934/3741411 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| api :POST, "/organizations", "Create an organization" | |
| param :name, String, :desc => "name for the organization" | |
| param :description, String, :desc => "description" | |
| def create | |
| label = params[:label] | |
| if params[:label].blank? | |
| # Convert name to label | |
| label = convert_str_to_label(params[:name]) | |
| end | |
| render :json => Organization.create!(:name => params[:name], :description => params[:description], :label => label).to_json | |
| end | |
| .... | |
| # Convert a string into an ASCII restricted label with spaces converted to underscore, eg: | |
| # "Some string with spaces" => "Some_string_with_spaces" | |
| def convert_str_to_label(original) | |
| spaces_to_underscores = original.tr(' ', '_') | |
| # URLEncode the string to go from UTF8 -> ASSCII | |
| URI::encode(spaces_to_underscores) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment