Closed cmendla closed 7 years ago
Hi @cmendla-cct
I don't think it's anything to do with the environment. ap
takes an object and pretty prints it. In your case you are passing it a string so there is not much for it to do other than putting some quotes around it.
When you call @observation.inspect you transform your observation
variable into a string. You don't need inspect when using awesome print as that's essentially what we are doing: http://ruby-doc.org/core-2.3.3/Object.html#method-i-inspect
What you probably want to do is ap(@observation), or in your case because you want to then convert it to be a html safe string you will instead want to use the ai
(stands for Awesome Inspect) method. So instead of:
<%= ap @observation.inspect.html_safe %>
you can write:
<%= @observation.ai.html_safe %>
I'm guessing in your console example the instance variables were not available in that context and so they defaulted to nil (which I agree is unintuitive, but this is just what Ruby does).
With your:
>> require "awesome_print"
=> false
again this is just another strange Ruby thing that catches out a lot of people. false
just means it's already been loaded. https://ruby-doc.org/core-2.3.3/Kernel.html#method-i-require If it can't require at all, it actually throws a https://ruby-doc.org/core-2.3.3/LoadError.html.
Hope that helps :)
It is working well now.
What you probably want to do is ap(@observation),
was the key.
Thanks
I installed awesome print but it doesn't seem to be formatting.
Gemfile
gem 'awesome_print', require: 'ap'
in my html.erb
What I see (removed middle part for readability)
<pre class="debug_dump">"#<Observation id: 344, employee_id: nil, supervisor_last_name: \"Smith\", supervisor_first_name: \"Greg\", department_id: 2, team_id: nil, . . . updated_at: \"2016-06-27 17:15:39\", date_discussed: \"2016-06-13\", reason: nil, points: nil, point_value_id: nil, supervisor_id: 117, employee_raw: \"[\\\"Chris Jones\\\"]\", supervisor_raw: nil, user_id: 87, testchk: nil>"</pre>
If I try using ap from the console, I get
I did run bundle install and it seems to be installed
My environment is
Other things I use with html_safe such as ckeditor do show up in an html format.