madebymany / sir-trevor-rails

Rails gem for Sir Trevor integration.
MIT License
149 stars 50 forks source link

Rails 4.2.1 issue #38

Closed SergeyKishenin closed 9 years ago

SergeyKishenin commented 9 years ago

With Rails 4.2.1 I get

You have the following errors:
There was a problem loading the contents of the document

In JS console:

Sorry there has been a problem with parsing the JSON SyntaxError: Unexpected token #

while with Rails 4.2.0 it works fine.

cbeer commented 9 years ago

We ran into the same problem with Rails 4.2.1. It looks like, under Rails 4.2.1:

<%= f.text_area :content %>

is no longer providing the string value of content, but we're getting the Ruby serialization instead:

[#&lt;SirTrevorRails::Blocks::TextBlock text=&quot;&lt;p&gt;text&lt;/p&gt;&quot;, isHtml=true&gt;]

A workaround seems to be doing something like:

<%= f.text_area :content, value: f.object['content'] %>
ninjabiscuit commented 9 years ago

Thanks for reporting. I’ll look into what we can do about getting this fixed

--  Andrew Walker ["@ninjabiscuit", "07886655448"] http://madebymany.com

On 24 March 2015 at 16:28:53, Chris Beer (notifications@github.com) wrote:

We ran into the same problem with Rails 4.2.1. It looks like, under Rails 4.2.1:

<%= f.text_area :content %>

is no longer providing the string value of content, but we're getting the Ruby serialization instead:

[#<SirTrevorRails::Blocks::TextBlock text="<p>text</p>", isHtml=true>]

A workaround seems to be doing something like:

<%= f.text_area :content, value: f.object['content'] %>

— Reply to this email directly or view it on GitHub.

adamcarlile commented 9 years ago

I've managed to fix this in my application by writing an initialiser to add a to_s method that constructs a JSON object for the block array.

module SirTrevorRails
  class BlockArray < Array
    def to_s
      {data: as_json}.to_json
    end
  end
end
zaparka commented 9 years ago

I have same issue with rails 4.2.3

milushov commented 9 years ago

same issue, my workaround is f.object.read_attribute(:content)

ninjabiscuit commented 9 years ago

This should be fixed now. We also have Travis running against a few different versions of ruby so things like this should get caught a little easier from now on

adamcarlile commented 9 years ago

Thanks @ninjabiscuit

ninjabiscuit commented 9 years ago

@adamcarlile np :+1: