Rails error model_path, lack of matching route "model.2"; should be "model / 2"

Something seems to be wrong with my routing routes. Usually I have to do something like <%= link_to Profile, user_path(@user||current_user) %>, and I continue my day. For some reason, I do not understand that mine is user_pathnot returning /user/:id, as I would expect it. Instead, it returns. /user.:id To test this, I downloaded a partial code with the following code.

application / view / users / _test.html.rb

<%= @user %><br>
<%= @user.id %><br>
<%= link_to user_path(@user), user_path(@user) %><br>
<%= new_user_path %><br>
<%= edit_user_path(@user) %><br>
<%= url_for(@user) %>

It returned

local: 3000 / test

#<User:0x007fb6cd341f08>
1
/user.1
/users/new
/users/1/edit
/user.1

, . edit_user_path(@user) , . Rails Routing Guide , . , , - Rails 3.1 Devise, Devise (, ?).

? (, , , ), , . ?

, , , , .

/routes.rb

Rails.application.routes.draw do

  root 'static#home'

  %w( 404 406 422 500 503 ).each do |code|
    get code, :to => "errors#show", :code => code 
  end 

  #USER PAGES
  get '/test' => 'users#test'
  get '/signup' => 'users#new'
  post '/user' => 'users#create'
  get '/user/list' => 'users#index'
  post '/user/' => 'users#update'
  get '/user/:id' => 'users#show'
  get 'profile', to: 'users#show'

  resources :users
end
+4
2

:

/routes.rb

Rails.application.routes.draw do

  root 'static#home'

  %w( 404 406 422 500 503 ).each do |code|
    get code, :to => "errors#show", :code => code 
  end 

  #USER PAGES
  get '/test' => 'users#test'
  get 'profile', to: 'users#show', as: :user_profile

  resources :users
end

... resources :users , .

, , , , , - URL-, , , (.. doesnt_have_an_id_path(@object) => /doesnt_have_an_id.1).

, . , (, , ). .

, users#show :id, . , , , .

, - , - /, .

+1

:

post '/user/' => 'users#update'
get '/user/:id' => 'users#show'

user_path, user named route. rake routes , :

Prefix Verb URI Pattern         Controller#Action
  user POST /user(.:format)     users#create
       GET  /user/:id(.:format) users#show

Prefix , . Rails user POST /user. , user_path /user /user/:id, . Rails , , . , get /user/some/more , Rails route user_some_more , user_some_more_path .

, POST, : post '/user/', as: nil GET , : get '/user/:id', as: 'user'. user_path(user) format/user/: id.

+1

Source: https://habr.com/ru/post/1692978/


All Articles