Rails: How to pass a url path to a form_for partial in Rails?
<p>I'm trying to pass a <code>url</code> and <code>variable</code> to a form partial in Rails.</p>

<hr>

<p><strong>Method #1:</strong><br>
This works, but I'd rather not hardcode <code>post_create_path</code> into the form, so that it can be used for #update as well.</p>

<p>new.html.erb</p>

<pre><code>&lt;%= render partial: 'shared/form', locals: { form: @form } %&gt;
</code></pre>

<p>_form.html.erb</p>

<pre><code>&lt;%= form_for form, url: post_create_path do |f| %&gt;
...
&lt;% end %&gt;
</code></pre>

<hr>

<p><strong>Method #2:</strong><br>
This does not work.</p>

<p>new.html.erb</p>

<pre><code>&lt;%= render partial: 'shared/form', locals: { form: @form, url: post_create_path } %&gt;
</code></pre>

<p>_form.html.erb</p>

<pre><code>&lt;%= form_for form, url: url do |f| %&gt;
...
&lt;% end %&gt;
</code></pre>

<p><strong>Error:</strong></p>

<blockquote>
  <p>undefined local variable or method `url' for #&lt;#:0x007f8d4d831fd0></p>
</blockquote>

<p><strong>What I've also tried:</strong></p>

<ol>
<li>Just <code>url</code> instead of <code>url:url</code> but getting the same error.</li>
<li>Following this thread: <a href="https://stackoverflow.com/questions/30138927/how-to-pass-url-to-partial-form">How to pass url to partial/form?</a></li>
</ol>

<p>I've been trying to make this work for a couple hours now and feel like I'm running out of options to try. Any help in pointing out what I'm doing wrong would be super appreciated!</p>