Open zamakkat opened 8 years ago
In the latest version of sir_trevor_rails SirTrevorRails::BlockArray#to_s
has been overwritten to return JSON representation of the array of blocks, which should make it work with form helpers.
Are you using the latest version of the gem (0.5.0)?
I am not sure this is the default and intended behavior but would appreciate any help with this issue.
I have a simple
Draft
model with acontent
JSON column on it. On the front-end, I am usingsimple_form
to generate a form and initialize the sir-trevor editor. With this setup everything works as it is supposed to. User edits on the editor, saves and JSON gets saved to the database. On refresh, the editor still loads the JSON and shows what the user previously saved.However, when I add the
sir_trevor_content :content
from the gem, things stop working. Since that helper method overrides the default getter, usingdraft.content
no longer returns the column values (the JSON) but returns an array ofSirTrevorRails:Blocks
. The only remaining way to actually get the JSON value to show in the editor is to useread_attribute
which doesn't really look very nice.I tried a workaround using
alias_method
and applysir_trevor_content
on the alias, still doesn't work. I also tried defining a custom method calledcontent_view
that returns thecontent
, then pass that tosir_trevor_content
but that doesn't work since in the concern, there is this line of codewhich restricts the use only to model attributes, not methods.
My current fix is simple although not very elegant. I just prefixed the method defined by
sir_trevor_content
withsir_trevor_
so that it doesn't override the default getter: https://github.com/zamakkat/sir-trevor-rails/commit/0a88182babf2d317e4bcec58b55997de6d014f0f Now, I can still usedraft.content
to freely edit the JSON using thesir-trevor
editor and then display it by callingdraft.sir_trevor_content
to show it in the views.Any other (better) workarounds and ways to fix the gem are welcomed and I can issue a PR if the owners are OK with this.
Cc: @shinnyx