I've been following the Ruby on Rails getting started guide and when they start using partials, they only pass model into form_with and not scope or url. Thanks in advance.
new.html.erb
<%= form_with scope: :article, url: articles_path, local: true do |form| %>
edit.html.erb
<%= form_with model: @article, local: true do |form| %>
_form.html.erb
<%= form_with model: @article, local: true do |form| %>
If you are creating/updating a model object, then you only need to pass model: @article option. Here @article is an object of Article class. In this case Rails convention-over-configuration will kick in and auto-generate the url so you don't have to pass it explicitly.
But, if you have a form, where there's no model object assoicated, e.g., a simple search form, then we can use scope option and have to pass url explicitly as in this case there's no model object associated therefore the url won't be auto-built.
In your case, it seems like you want to create or update an article object. So this should work.
<%= form_with model: @article, local: true do |form| %>
Hope that helped!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With