ruby - sinatra sending headers and body -


I am posting to Sinatra with a web contact form. Which works perfectly, I need to set custom headers because it is a CORS request that works even right.

But when I want to send json for the request: Status and: Message is to send me a Sinatra object and not suitable Jason.

In addition to this, I see the print out in my log, not in the message body but in the header.

Code snippet:

  header "access-control-permission-origin" = & gt; "*", "Access-Control-Permission-Methods" = & gt; "Post", "Access-Control-Permission-Headers" = & gt; "Content-type", "access-control-max-age" = & gt; "86400" if the consultation [: Email]. Empty? Response [: status] = "error" response [: message] = "no email" page response. Inspector body response. Response [: position] = "error" response [: message] = "no message?" Body response.to_json elsif ...  

log file:

  "#inetax :: response: 0x007fc62bfed2f8 @ position = 200, @adder = {\ "Content-Type \" = & gt; \ "Application / JS \", \ "Access-Control-Permission-Origin \" = & gt; \ "* \", \ "Access-Control-App- Method \ "= & Gt; \" POST \ ", \" access-control-app-headers \ "= & gt; \" content-type \ ", \" access-control-max-age \ "= & gt; ; \ "86400 \",: Status = & gt; \ "Error \",: Message = & gt; \ "No Email \"}, @Chart = False, Author @ # & lt; Proc: 0x007fc62bfecf88 @ /Users/gtheys/.rbenv/versions/2.0.0- P247 / lib / ruby ​​/ gems / 2.0.0 / gems / rack-1.5.2 / lib / rack / response.rb: 27 (lambda)>, @ block = blue, length = 0, @body []> gt = , "127.0.0.1 - - [01 / August / 2014 10:48:57]" Post / "200 39 0.0077  

problem resolved

delete:

  response [: status] = "error" response [: message] = "no email No " 

Add:

  {: status => "Error",: Message = & gt; "No email"} To_json  

and it works


Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -