title: Syntax to route Rails form_for to custom controller
body: <p>Have tried forums, documentation and blog suggestions. They converge on syntax that for me does not properly save AND route through desired controller.</p>
  
  <p>Big picture, I have two software applications that share functionality. To implement shared functionality, I had Rails generate Shared::Widgets. This MVC works just fine. No problem viewing, updating, creating, or deleting using standard shared/widgets &amp; etc routing.</p>
  
  <p>Then, for the product-specific functionality, I created two controllers: Product1::Widgets and Product2::Widgets. Both inherit from Shared::Widgets controller. Both are empty except for product-specific layouts.</p>
  
  <p>This scheme almost works. When I route to product1/widgets, it sets layout to product1 and invokes index method of shared/widgets. The result is display of shared/widgets/index.html.erb with product1 layout. Similarly, when I route to product2/widgets, this sets product2 layout and invokes index method of shared/widgets. The result is display of shared/widgets/index.html.erb with product2 layout. Perfect.</p>
  
  <p>But now we get to the form_for. Because it implements the rails magic, it really really wants to route directly to Shared::Widgets controller. But that's not what I want. I want it to route to the appropriate product controller so as to set layout. The rails generated form_for was something like this:</p>
  
  <pre><code>form_for(@shared_widget, :html =&gt; { :class =&gt; "form"}) do |f|
  </code></pre>
  
  <p>I tried:</p>
  
  <pre><code>form_for([:product1, @widget], :html =&gt; { :class =&gt; "form"}) do |f| 
  </code></pre>
  
  <p>but that duplicates namespace (product1_widget_shared_widget_path).</p>
  
  <p>I tried the following three formats, all of which seem to route correctly, and save the record, but the record is empty (columns are blank):</p>
  
  <pre><code>form_for(@widget, url =&gt; "product1/widget", :html =&gt; { :class =&gt; "form"}) do |f| 
  
  form_for(@widget, url =&gt; url_for(:controller =&gt; "widget"), :html =&gt; { :class =&gt; "form"}) do |f| 
  
  form_for(@widget, url =&gt; url_for(:controller =&gt; "widget", :action =&gt; "create"), :html =&gt; { :class =&gt; "form"}) do |f| 
  </code></pre>
  
  <p>Any help? If the above code has spelling errors, it is due to transcription. The actual code I used passed the interpreter. Thank you.</p>