Skip to content

Instantly share code, notes, and snippets.

@mccun934
Created September 18, 2012 05:21
Show Gist options
  • Select an option

  • Save mccun934/3741411 to your computer and use it in GitHub Desktop.

Select an option

Save mccun934/3741411 to your computer and use it in GitHub Desktop.
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