Home>

When you call the show action in Rails, the URL displayed will change to the intended screen, but will be as follows.
http://localhost:3000/mypage.6

I think it is correct to display "/mypage.6" → "/mypage/6", but I'm not sure what's wrong.
This is Rails calling mypages#show after Devise login.
Professor, please.

⬛︎ route.db

Rails.application.routes.draw do
  root to:'tops#index'
  devise_for :users
  resource:mypage
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

⬛︎ ApplicationController

class ApplicationController


⬛︎ MypagesController

class MypagesController
  • Answer # 1

    resource :mypage


    I think that is the cause.
    This route cannot be called on /mypage/:id.
    Is it possible to achieve what you want to do with any of the following?

    Method 1
    routes.rb resources :mypages
    url /mypages/:id

    Method 2
    routes.rb resource :mypage
    url /mypage/

    Method 3
    get'mypage/:id', to:'mypages#show'
    url /mypage/:id

    I think it is good to do it while checking the helper method, url and controller with rails routes.

Related articles