Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

form_with problem #4

Open
GATAKAWAKACHICO opened this issue Jul 26, 2017 · 2 comments
Open

form_with problem #4

GATAKAWAKACHICO opened this issue Jul 26, 2017 · 2 comments

Comments

@GATAKAWAKACHICO
Copy link

@paul-at Thank you for providing an awesome gem.
I'd like to contribute to your repo. I found that it goes wrong when I use form_with method because of the line as below.
https://github.com/paul-at/quill-rails5/blob/master/lib/quill/rails5/view_helpers.rb#L42
The error log is here.

undefined method `[]' for nil:NilClass
lib/quill/rails5/view_helpers.rb:42:in `quill_field'

form_with method doesn't generate

form.options[:html][:id]

So, I needed to set an form id like this after that it successfully worked.

<% # before %>
<%= form_with(model: foo, local: true) do |form| %>

<% # after %>
<%= form_with(model: foo, local: true, html: {id: 'foo'} ) do |form| %>

How do I fix this problem and push PR?

FYI: DHH said that rails should unify form_tag and form_for into form_with.
rails/rails#25197

@paul-at
Copy link
Owner

paul-at commented Jul 27, 2017

Thanks for sharing this workaround!

I think form_with should have some way to access form id as well?

@GATAKAWAKACHICO
Copy link
Author

GATAKAWAKACHICO commented Jul 27, 2017

@paul-at
I think form_with method doesn't generate form id automatically by default.
http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_with
I quote from this doc.

# An existing model makes an update form and fills out field values:
<%= form_with model: Post.first do |form| %>
  <%= form.text_field :title %>
<% end %>
# =>
<form action="/posts/1" method="post" data-remote="true">
  <input type="hidden" name="_method" value="patch">
  <input type="text" name="post[title]" value="<the title of the post>">
</form>

# Though the fields don't have to correspond to model attributes:
<%= form_with model: Cat.new do |form| %>
  <%= form.text_field :cats_dont_have_gills %>
  <%= form.text_field :but_in_forms_they_can %>
<% end %>
# =>
<form action="/cats" method="post" data-remote="true">
  <input type="text" name="cat[cats_dont_have_gills]">
  <input type="text" name="cat[but_in_forms_they_can]">
</form>

Currently, I use rails 5.1.2 and because of above, posted an PR.
Could you try to create some form with using form_with method?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants