Closed aandrieu closed 4 years ago
The selectors send in the JSON over action cable are not the same that the one generated by the the form helper for models nested in module.
In my example I have a Webhook model inside a Triggers module.
From rails console:
a = Triggers::Webhook.create() => ... a.class.to_s.underscore => "triggers/webhook"
It matches the selectors I saw in the JSON paylod:
"selector"=>"#triggers/webhook_title_container"
This payload has 2 issues:
/
document.querySelector
Still in my example it is what I have in my HTML:
<input name="triggers_webhook[title]" id="triggers_webhook_title_container"/>
As you can see id is not the same as the generated selector.
Use the same function as the rails form_helper to compute the correct name. https://github.com/rails/rails/blob/98ddee2b6e3e4da5ad84dcc1313493b04935711b/actionview/lib/action_view/helpers/form_helper.rb#L442
I'm a newbie in Rails so maybe it is not the right way fix this issue. Please do not hesitate to improve my solution 😄 .
I am so glad that I finally get to git blame and see that something is totally @joshleblanc's fault. ;)
git blame
I have never worked with param_key but it seems legitimately perfect. Great catch!
Bug
The selectors send in the JSON over action cable are not the same that the one generated by the the form helper for models nested in module.
Example
In my example I have a Webhook model inside a Triggers module.
From rails console:
It matches the selectors I saw in the JSON paylod:
This payload has 2 issues:
/
are not recognized bydocument.querySelector
as valid css selectorsStill in my example it is what I have in my HTML:
As you can see id is not the same as the generated selector.
Solution
Use the same function as the rails form_helper to compute the correct name. https://github.com/rails/rails/blob/98ddee2b6e3e4da5ad84dcc1313493b04935711b/actionview/lib/action_view/helpers/form_helper.rb#L442
I'm a newbie in Rails so maybe it is not the right way fix this issue. Please do not hesitate to improve my solution 😄 .