Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 Route: button_to HTML INPUT Action not working
    primarykey
    data
    text
    <p>I have a strange problem that I think has to do with routes.</p> <p>In my "view" I have this:</p> <pre><code>&lt;%= button_to "New Item", new_proposal_pitem_path(@proposal), :method =&gt; :get %&gt; </code></pre> <p>I want to click the "New Item" button, and create a new pitem for a proposal. This generates the HTML I would expect:</p> <pre><code>&lt;form method="get" action="/proposals/1234/pitems/new" ...&gt;&lt;input ...&gt;&lt;/form&gt; </code></pre> <p>However, what really happens is, when I click on the button it attempts a GET on /proposals/1234 rather than /proposals/1234/pitems/new. This gives me a "show" page rather than a "new" page. Interestingly, I can manually put the {site}/proposals/1234/pitems/new directly into the web browser HTTP address and get what I want (the "new" page). But rails is, on its own, translating it first to /proposals/1234 if I leave it to its own in response to the button click.</p> <p>To make this more mysterious, I have a similar item on the same form which looks exactly the same way:</p> <pre><code>&lt;%= button_to "New Payment", new_proposal_payment_path(@proposal), :method =&gt; :get %&gt; </code></pre> <p>which generates the same HTML as the other case:</p> <pre><code>&lt;form method="get" action="/proposals/1234/payments/new" ...&gt;&lt;input ...&gt;&lt;/form&gt; </code></pre> <p>But this one works! It takes me right to /proposals/1234/payments/new when I click the button, just like I'd expect. I just don't understand what makes these behave differently.</p> <p>My full routes file looks like this:</p> <pre><code>TCoB::Application.routes.draw do resources :proposals do resources :pitems, :payments get 'list', :on =&gt; :collection end resources :pitems do get 'list', :on =&gt; :collection end resources :invoices do resources :iitems, :payments get 'list', :on =&gt; :collection end resources :iitems do get 'list', :on =&gt; :collection end resources :payments do get 'list', :on =&gt; :collection end resources :ids resources :clients do resources :proposals, :invoices # Route GET /cients/list get 'list', :on =&gt; :collection get 'list_proposals', :on =&gt; :collection get 'list_invoices', :on =&gt; :collection end get "home/index" root :to =&gt; "home#index" end </code></pre> <p>Can someone shed light on this issue?</p> <p>Thanks!</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.
 

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