Note that there are some explanatory texts on larger screens.

plurals
  1. POParse array output into table -- Ruby Rails
    primarykey
    data
    text
    <p>I am integrating someone else's library in Ruby/Rails that provides custom class which returns output from an API. This is an example of the code and output that comes when the class and custom method is submitted in the rails console:</p> <pre><code>CustomClass.mymethod 'this is a normal string of text that i am submitting to the rails console.' =&gt; #&lt;CustomClass::MyMethod:0x10159d4e8 @info={"output1"=&gt;"15", "output2"=&gt;"1"}, @otherinfo={0}, @moreinfo={0}, @stillmore={"violations"=&gt;"0"}&gt; </code></pre> <p>In my application, I call this on a user-submitted text post (called "content") &amp; put the output into a column associated with that post in the "posts" table. Right now this is being done within the "create" action in my posts controller:</p> <pre><code>@post.output = CustomClass.mymethod(@post.content) </code></pre> <p>Which posts the right output, but its formatting is a mess:</p> <p>--- !ruby/object:CustomClass::MyMethod otherinfo: {} moreinfo: {} info: ? !ruby/string:REXMLUtiliyNodeString str: output1 attributes: {} : !ruby/string:REXMLUtiliyNodeString str: '1' attributes: {} ? !ruby/string:REXMLUtiliyNodeString str: output2 attributes: {} : !ruby/string:REXMLUtiliyNodeString str: '15' attributes: {} stillmore: {0} </p> <p>Is there an easy way to clean up the output and write each piece into different columns of my posts table, or can I grab just one of the array objects (@otherinfo / otherinfo: {}) and write it into the posts table?</p> <p>I am pretty new to Ruby/Rails so I appreciate your patience and help! I am sure this is something simple but I couldn't find anything today that got me where I needed to be. I'll even appreciate links that will help me understand how to learn the right commands to do the parsing or conversion of the text string.</p> <p>Thanks!</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