Rails debugging method outputs binary values ​​only

I have tried the internet as best as possible for this problem, but I am completely bound by the keyword! binary, because search engines (including internal stackoverflow search!) erase the exclamation mark.

I work through the Rails tuorial at http://ruby.railstutorial.org - which for the most part has been a great resource. One of the useful things that I have at the bottom of my application.html.erb page:

<%= dump(params) %> 

I was told that the specific scenario should output the following:

 --- !map:ActiveSupport::HashWithIndifferentAccess commit: Sign in session: !ActiveSupport::HashWithIndifferentAccess password: "" email: "" authenticity_token: BlO65PA1oS5vqrv591dt9B22HGSWW0HbBtoHKbBKYDQ= action: create controller: sessions 

Instead, I get the following:

 --- !ruby/hash:ActiveSupport::HashWithIndifferentAccess !binary "dXRmOA==": βœ“ !binary "YXV0aGVudGljaXR5X3Rva2Vu": ItPS/PZ+avYOGD2ckict1urJpatw1HinrVyk385/Yt8= !binary "c2Vzc2lvbg==": !ruby/hash:ActiveSupport::HashWithIndifferentAccess !binary "dXNlcm5hbWU=": '' !binary "cGFzc3dvcmQ=": '' !binary "Y29tbWl0": Sign in action: create controller: sessions 

This is much less useful.

I assume that rails are able to output data as it is in memory (i.e. a binary form), or can decode the data and display it in plain text.

I obviously get the right data, only in the wrong form.

The question is how to get a text version?

The second question is why does heck make a site like stackoverflow does not have a mechanism to include special characters in search queries? IMO fundamental failure

+6
source share
3 answers

Can you try switching from .dump to .inspect like this?

 <%= params.inspect %> 
+4
source

I believe that the string encoding for the key, which is strangely presented as !binary , although it does not have non-7-bit ASCII characters. Values ​​are encoded as base-64 to render them in text format:

 "dXRmOA==".unpack('m') # => ["utf8"] 

This may be an artifact of your environment where the standard string encoding is irregular.

+1
source

It's definitely too late to help you, but hopefully others who come up with this question when working with Michael Hartl Rails tutorials may be helpful.

The Rails Tutorials 2nd edition uses sqlite3 1.3.5 stone.

This answer explains the differences in how the material is parsed ... YAML exits from the rails console

This worked for me - I upgraded the sqlite3 stone to 1.3.6 in my Gemfile, ran bundle install and killed / restarted the rails server. After this binary! Changed back to the text keys you expect.

0
source

Source: https://habr.com/ru/post/910296/


All Articles