Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can set up the routing manually, if you're that concerned about what URL is going to show. For what you want, you can have a <code>GET</code> to <code>/foos/new</code> render your form, and a <code>POST</code> to the same URL do the creation:</p> <pre><code>map.with_options :controller =&gt; :foos do |foo| foo.new_foo '/foos/new', :conditions =&gt; {:method =&gt; :get}, :action =&gt; :new foo.create_foo '/foos/new', :conditions =&gt; {:method =&gt; :post}, :action =&gt; :create foo.foos '/foos', :conditions =&gt; {:method =&gt; :get}, :action =&gt; :index end </code></pre> <p>This should work without requiring any changes to your controller (yay!) - all three actions from your example are taken care of. The few disclaimers:</p> <ol> <li>This is based on my routing for a 2.3.8 app - some syntax (semantics?) changes are probably required to get it into Rails 3 routing style.</li> <li>My attempts to mix this style of routing with <code>map.resources</code> have failed horribly - unless you're more familiar with this than me, or Rails 3 routing is better (both easily possible), you'll have to do this for every route to the controller.</li> <li>And finally, don't forget to add <code>/:id</code>, <code>(.:format)</code>, etc. to the routes that need them (none in this example, but see #2).</li> </ol> <p>Hope this helps!</p> <p><strong>Edit:</strong> One last thing - you'll need to hard-code the URL in your <code>form_for</code> helper on <code>/foos/new.html.erb</code>. Just add <code>:url =&gt; create_foo_path</code>, so Rails doesn't try to post to <code>/foos</code>, which it will by default (there might be a way to change the creation URL in the model, but I don't know of it, if there is one).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload