Render json response from controller to view












0















I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?




"{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"




   respond_to do |format|
format.json { render :json => result }
end









share|improve this question





























    0















    I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?




    "{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"




       respond_to do |format|
    format.json { render :json => result }
    end









    share|improve this question



























      0












      0








      0








      I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?




      "{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"




         respond_to do |format|
      format.json { render :json => result }
      end









      share|improve this question
















      I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?




      "{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"




         respond_to do |format|
      format.json { render :json => result }
      end






      ruby-on-rails






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 3 at 9:38









      Lenin Raj Rajasekaran

      16.1k1173116




      16.1k1173116










      asked Jan 3 at 9:34









      Raja1983Raja1983

      237




      237
























          2 Answers
          2






          active

          oldest

          votes


















          0














          There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:



          var tr = '<tr><td>';
          tr += jsonResponse.firstAttribute;
          tr += '</td><td>';
          tr += jsonResponse.secondAttribute;
          tr += '</td>';
          ...
          $('#you-table-body-id').append(tr);


          by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.






          share|improve this answer
























          • Thanks for your input.

            – Raja1983
            Jan 3 at 16:35



















          0














          The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:



          JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")


          This will change it to:



          {"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}


          You can render is as json:



          respond_to do |format|
          format.json { render json: JSON.parse(result) }
          end





          share|improve this answer
























          • ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

            – Raja1983
            Jan 3 at 10:01













          • You want to show it in table?

            – Talha Junaid
            Jan 3 at 10:17











          • yes.I want show as table.

            – Raja1983
            Jan 3 at 10:26











          • You are using javascript to call this JSON returning action?

            – Talha Junaid
            Jan 3 at 10:31











          • yes.We are using java script.

            – Raja1983
            Jan 3 at 10:32












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019543%2frender-json-response-from-controller-to-view%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:



          var tr = '<tr><td>';
          tr += jsonResponse.firstAttribute;
          tr += '</td><td>';
          tr += jsonResponse.secondAttribute;
          tr += '</td>';
          ...
          $('#you-table-body-id').append(tr);


          by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.






          share|improve this answer
























          • Thanks for your input.

            – Raja1983
            Jan 3 at 16:35
















          0














          There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:



          var tr = '<tr><td>';
          tr += jsonResponse.firstAttribute;
          tr += '</td><td>';
          tr += jsonResponse.secondAttribute;
          tr += '</td>';
          ...
          $('#you-table-body-id').append(tr);


          by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.






          share|improve this answer
























          • Thanks for your input.

            – Raja1983
            Jan 3 at 16:35














          0












          0








          0







          There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:



          var tr = '<tr><td>';
          tr += jsonResponse.firstAttribute;
          tr += '</td><td>';
          tr += jsonResponse.secondAttribute;
          tr += '</td>';
          ...
          $('#you-table-body-id').append(tr);


          by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.






          share|improve this answer













          There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:



          var tr = '<tr><td>';
          tr += jsonResponse.firstAttribute;
          tr += '</td><td>';
          tr += jsonResponse.secondAttribute;
          tr += '</td>';
          ...
          $('#you-table-body-id').append(tr);


          by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 15:41









          Rodrigo EcheconeaRodrigo Echeconea

          963




          963













          • Thanks for your input.

            – Raja1983
            Jan 3 at 16:35



















          • Thanks for your input.

            – Raja1983
            Jan 3 at 16:35

















          Thanks for your input.

          – Raja1983
          Jan 3 at 16:35





          Thanks for your input.

          – Raja1983
          Jan 3 at 16:35













          0














          The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:



          JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")


          This will change it to:



          {"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}


          You can render is as json:



          respond_to do |format|
          format.json { render json: JSON.parse(result) }
          end





          share|improve this answer
























          • ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

            – Raja1983
            Jan 3 at 10:01













          • You want to show it in table?

            – Talha Junaid
            Jan 3 at 10:17











          • yes.I want show as table.

            – Raja1983
            Jan 3 at 10:26











          • You are using javascript to call this JSON returning action?

            – Talha Junaid
            Jan 3 at 10:31











          • yes.We are using java script.

            – Raja1983
            Jan 3 at 10:32
















          0














          The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:



          JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")


          This will change it to:



          {"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}


          You can render is as json:



          respond_to do |format|
          format.json { render json: JSON.parse(result) }
          end





          share|improve this answer
























          • ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

            – Raja1983
            Jan 3 at 10:01













          • You want to show it in table?

            – Talha Junaid
            Jan 3 at 10:17











          • yes.I want show as table.

            – Raja1983
            Jan 3 at 10:26











          • You are using javascript to call this JSON returning action?

            – Talha Junaid
            Jan 3 at 10:31











          • yes.We are using java script.

            – Raja1983
            Jan 3 at 10:32














          0












          0








          0







          The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:



          JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")


          This will change it to:



          {"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}


          You can render is as json:



          respond_to do |format|
          format.json { render json: JSON.parse(result) }
          end





          share|improve this answer













          The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:



          JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")


          This will change it to:



          {"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}


          You can render is as json:



          respond_to do |format|
          format.json { render json: JSON.parse(result) }
          end






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 3 at 9:57









          Talha JunaidTalha Junaid

          230210




          230210













          • ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

            – Raja1983
            Jan 3 at 10:01













          • You want to show it in table?

            – Talha Junaid
            Jan 3 at 10:17











          • yes.I want show as table.

            – Raja1983
            Jan 3 at 10:26











          • You are using javascript to call this JSON returning action?

            – Talha Junaid
            Jan 3 at 10:31











          • yes.We are using java script.

            – Raja1983
            Jan 3 at 10:32



















          • ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

            – Raja1983
            Jan 3 at 10:01













          • You want to show it in table?

            – Talha Junaid
            Jan 3 at 10:17











          • yes.I want show as table.

            – Raja1983
            Jan 3 at 10:26











          • You are using javascript to call this JSON returning action?

            – Talha Junaid
            Jan 3 at 10:31











          • yes.We are using java script.

            – Raja1983
            Jan 3 at 10:32

















          ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

          – Raja1983
          Jan 3 at 10:01







          ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?

          – Raja1983
          Jan 3 at 10:01















          You want to show it in table?

          – Talha Junaid
          Jan 3 at 10:17





          You want to show it in table?

          – Talha Junaid
          Jan 3 at 10:17













          yes.I want show as table.

          – Raja1983
          Jan 3 at 10:26





          yes.I want show as table.

          – Raja1983
          Jan 3 at 10:26













          You are using javascript to call this JSON returning action?

          – Talha Junaid
          Jan 3 at 10:31





          You are using javascript to call this JSON returning action?

          – Talha Junaid
          Jan 3 at 10:31













          yes.We are using java script.

          – Raja1983
          Jan 3 at 10:32





          yes.We are using java script.

          – Raja1983
          Jan 3 at 10:32


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019543%2frender-json-response-from-controller-to-view%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Mossoró

          Error while reading .h5 file using the rhdf5 package in R

          Pushsharp Apns notification error: 'InvalidToken'