I am working with Devise gem and I created a show
page for users. My idea was to make a simple path like www.website.com/:id
and I configured it as shown below:
devise_for :users, path: '', path_names: {sing_in: "login", sing_out:
"signout", sing_up: "signup", edit: "edit"},
:controllers => {:registrations => :registrations }
resources :users, only: [:show]
get '/:id' => 'users#show', as: :profile
My routes work fine but besides show
page, I have pages under static controller
for example about
page. I want to be able to access it like www.website.com/about
, here is how I define my static routes
:
get '/about', to: 'static#about'
Now, if I am trying to redirect to about page
, I am getting an error:
ActiveRecord::RecordNotFound in UsersController#show
Couldn't find User with 'id'=about
Here is my users_controller.rb
:
class UsersController < ApplicationController
def show
@user = User.find_by_id(params[:id])
@services = @user.services
end
...
end
I tried to search for the similar errors but haven't found anything like this. Can someone please tell me what I am doing wrong?
Thank you for your help and time.
Two things here:
In this case, I suspect that your single level routes are being defined your get '/:id'
route. Therefore, that route is catching all requests which are /anything
because the router thinks anything
is a parameter.
Simply move your route definition below any other /about
etc routes so that they are matched first.
Like this:
get '/about', to: 'static#about'
get '/:id' => 'users#show', as: :profile
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With