Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get json structure in Rails?
    primarykey
    data
    text
    <p>my application should sent structure via json, that functions works fine:</p> <pre><code>function send_json() { var formData = form2object('myForm'); var json_data = JSON.stringify(formData, null, '\t'); $.post("", json_data); } </code></pre> <p>It create json_data and send it via post. But I don't understand how to catch this data on another side, can you help me ? I should take this structure and make some actions with it.</p> <p>when i send data i got json:</p> <pre><code>{ "type": "test", "ttl": "1", "amount": "1", "rules": { "rule1": "1", "value1": "4444", "stackcount1": "1", "rule2": "2", "value2": "333", "stackcount2": "2" }} </code></pre> <p>In the contoller i wrote this:</p> <pre><code>class AdminController &lt; ApplicationController def index @json_string = params[:amount] if !@json_sting.nil? @json_string = JSON.parse(params[:amount]) end end end </code></pre> <p>in the view(haml) i wrote:</p> <pre><code>=@json_string </code></pre> <p>It doesn't work !</p> <p>But wireshark shows:</p> <pre><code>POST /admin/ HTTP/1.1 Host: localhost:3000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20100101 Firefox/14.0.1 Accept: */* Accept-Language: ru-ru,ru;q=0.8,en-us;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate DNT: 1 Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://localhost:3000/admin/ Content-Length: 192 Cookie: _GiftSenderTool_session=BAh7BzoQX2NzcmZfdG9rZW4iMTVyNVJCMTBvcGpKSk5OcFN4bW15YVlpRlF1TUNtb1gwZkY0bTRuRHlsNnM9Ig9zZXNzaW9uX2lkIiU4ZjFjNTNjNTY0MTQ1MGExNmFiODcxZGEyYzU5ZTkxMg%3D%3D--f21bf3b96edc3bc551c8de68acc6da17685d58b4 Pragma: no-cache Cache-Control: no-cache { ."type": "test", ."ttl": "1", ."amount": "1", ."rules": { .."rule1": "1", .."value1": "4444", .."stackcount1": "1" .}, ."authenticity_token": "n3B6D/Km9zOgOzlosK/OLHyTCDLk3MyCTlTBinfQcnY=" } </code></pre> <p>It means that i can't get data.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload