title: Rails form_for that uses STI base class
body: <p>I've got a pretty simple (I think) single-table inheritance (STI) setup in my Rails app.</p>
  
  <p>There is a User model with a nested resource Post.
  Using STI, I have it so that some Posts can be Post::Urgent objects.</p>
  
  <p>I noticed that my URL helpers like <code>&lt;%= [@user, @post] %&gt;</code> needed to be hard-coded to <code>&lt;%= user_post_path[@user, @post] %&gt;</code> or else I'd end up seeing errors about Rails not finding the <code>user_post_urgent_path</code> method. Okay, that was reasonably easy.</p>
  
  <p>(An alternate way of doing this is also <code>&lt;%= [@user, post: @post] %&gt;</code>.)</p>
  
  <p>Well, for some reason I'm not able to figure out how to make the <code>form_for</code> method adjusted in the same way. When I write simply</p>
  
  <pre><code>&lt;%= form_for [@user, @post] do |f| %&gt;
  </code></pre>
  
  <p>, I get similar errors to the URL helper case, but in the form context: <code>undefined method 'user_post_urgen_path'</code>.</p>
  
  <p>I fixed this by specifying:</p>
  
  <pre><code>&lt;%= form_for [@user, @post], url: :user_post do |f| %&gt;
  </code></pre>
  
  <p>But this doesn't completely work, because when I go to submit the form, I get problems in my controller, saying that strong parameters line <code>params.require(:post)</code> failed:</p>
  
  <pre><code>param is missing or the value is empty: post
  </code></pre>
  
  <p>If I inspect the <code>params</code> I find that the form is passing a <code>post_urgent</code> object and not a <code>post</code> object.</p>
  
  <p>I could, of course, manually put in some logic that always says <code>if !params[:post] and params[:post_urgent], then params[:post] = params[:post_urgent]</code>. But that just seems <em>way</em> too hacky, especially for Rails.</p>
  
  <p>Is there a better way to make a form like this "just work" regardless of what subclass of the Post model it actually happens to be?</p>