Note that there are some explanatory texts on larger screens.

plurals
  1. POStrange behavior of Ruby on Rails Routing
    primarykey
    data
    text
    <p>I am a Ruby newbie and I have been struggling with the following routing problem:</p> <p>I have a Publishers controller in my app, and I want to use it as a singular resource, so a logged-in publisher could go to his profile using the /publisher route.</p> <p>My routes file has the following </p> <pre><code>resources :publishers, :only =&gt; [:index, :show, :edit, :update] resource :publisher, :only =&gt; [:show, :edit, :update] </code></pre> <p>And in my view controller I have the link</p> <pre><code>&lt;li&gt;&lt;%= link_to "View General Settings", publishers_path(@publisher) %&gt;&lt;/li&gt; </code></pre> <p><strong>The problem: the links is translated to URL <code>/publisher.1</code> (instead of <code>publisher/1</code>)</strong></p> <p>(<code>.1</code> represents <code>publisher_id</code>; when the <code>publisher_id</code> is 2, it renders to <code>/publisher.2</code>)</p> <p><strong>Any suggestions as to why this happens, and how to fix it?</strong></p> <p>I post here my routes:</p> <pre><code> publishers GET /publishers(.:format) {:action=&gt;"index", :controller=&gt;"publishers"} edit_publisher GET /publishers/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"publishers"} publisher GET /publishers/:id(.:format) {:action=&gt;"show", :controller=&gt;"publishers"} PUT /publishers/:id(.:format) {:action=&gt;"update", :controller=&gt;"publishers"} POST /publisher(.:format) {:action=&gt;"create", :controller=&gt;"publishers"} new_publisher GET /publisher/new(.:format) {:action=&gt;"new", :controller=&gt;"publishers"} GET /publisher/edit(.:format) {:action=&gt;"edit", :controller=&gt;"publishers"} GET /publisher(.:format) {:action=&gt;"show", :controller=&gt;"publishers"} PUT /publisher(.:format) {:action=&gt;"update", :controller=&gt;"publishers"} </code></pre> <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