Pass json with special characters angularjs to ruby


I need to make a search form, where the back end used is ruby and front end is angular. the search query is generated in angular in json format and is passed to ruby via restangular service.

Its working fine. But when we tested the search string with semicolon it returned 500 Internal error. The first line puts params[:search] gives {"content":"my search is for the actual json string {"content":"my search is ; and :", "options":[]}

Please help me on how to handle it “;” also please let me know what all characters I need to be handled.


You need to encode your params first.

So the encoded params will be:
{"content":"my search is %3B and :", "options":[]}

The following is also valid:

You can encode URL using:

I am sure Angular will must have some library to encode the URLs.

You could also use native Javascript URL encoder.

The similar question was already answered on SO.

Answered By – Kartikey Tanna

Answer Checked By – Dawn Plyler (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.