You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 a content JSON column on it. On the front-end, I am using simple_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, using draft.content no longer returns the column values (the JSON) but returns an array of SirTrevorRails:Blocks. The only remaining way to actually get the JSON value to show in the editor is to use read_attribute which doesn't really look very nice.
I tried a workaround using alias_method and apply sir_trevor_content on the alias, still doesn't work. I also tried defining a custom method called content_view that returns the content, then pass that to sir_trevor_content but that doesn't work since in the concern, there is this line of code
content=read_attribute(attribute)
which 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 with sir_trevor_ so that it doesn't override the default getter: zamakkat@0a88182
Now, I can still use draft.content to freely edit the JSON using the sir-trevor editor and then display it by calling draft.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.
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:zamakkat@0a88182
Now, I can still use
draft.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
The text was updated successfully, but these errors were encountered: