Note that there are some explanatory texts on larger screens.

plurals
  1. PORails' resource has 'show' mapped without an ID and creates /users.id links instead of /users/id
    primarykey
    data
    text
    <p>For my current routing, the following ruby on rails code:</p> <pre><code>&lt;%= link_to current_user.name, users_path(current_user) %&gt; </code></pre> <p>which produces a link like the following:</p> <pre><code>&lt;a href="/users.1"&gt;name&lt;/a&gt; </code></pre> <p>In turn, Ruby on Rails has a hard time understanding this as it expects the <code>1</code> to be the format:</p> <pre><code>ActiveRecord::RecordNotFound in UsersController#show Couldn't find User without an ID Request Parameters: {"format"=&gt;"1"} </code></pre> <p>Which doesn't exactly make sense for Rails to route it like that, since it much rather should be <code>/users/1</code>. Trying this by hand, however, gives the following result:</p> <pre><code>Routing Error No route matches "/users/1" </code></pre> <p>Having the ID entered per hand with an ?id= param, such as <code>/users?id=1</code>, works fine.</p> <p>The issue is, I don't understand where the users.id comes from, nor how to fix - my routing file looks like</p> <pre><code>routes::Application.routes.draw do get "register" =&gt; "users#new", :as =&gt; "register" get "login" =&gt; "sessions#new", :as =&gt; "login" post "login" =&gt; "sessions#create", :as =&gt; "do_login" get "logout" =&gt; "sessions#destroy", :as =&gt; "logout" resource :users root :to =&gt; "pages#welcome" end </code></pre> <p>All actions but the one mentioned above work fine, though I'd like to find out why. <code>rake routes</code> lays it out like the following:</p> <pre><code> users POST /users(.:format) {:action=&gt;"create", :controller=&gt;"users"} new_users GET /users/new(.:format) {:action=&gt;"new", :controller=&gt;"users"} edit_users GET /users/edit(.:format) {:action=&gt;"edit", :controller=&gt;"users"} GET /users(.:format) {:action=&gt;"show", :controller=&gt;"users"} PUT /users(.:format) {:action=&gt;"update", :controller=&gt;"users"} DELETE /users(.:format) {:action=&gt;"destroy", :controller=&gt;"users"} </code></pre> <p>The issue here seems to be that users#show seems to have taken the place of users#index, which would be the correct thing to do for /users. Since this is all pretty much default routing with no custom routes in terms of the issue on hand, I'm quite clueless here. Any ideas?</p> <p>Edit: The users#show code is as simple as:</p> <pre><code>class UsersController &lt; ApplicationController def show @user = User.find(params[:id]) end end </code></pre>
    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