Not getting a [:id] parameter from url, Default route is not working

When I request a URL as follows:

http://localhost:3000/password_resets/edit/4RghIKJNygEDswIuuCo

I'm not getting the [:id] parameter, i.e. 4RghIKJNygEDswIuuCo.

Here is my route file, are there any modifications required for this?

ActionController::Routing::Routes.draw do |map|

  match 'primary', :to => 'pages#primary', :as => "primary"
  match 'admins', :to => 'admin_users#list', :as => "admins"

  match 'login', :to => 'user_sessions#new', :as => "login"
  match 'logout', :to => 'user_sessions#destroy', :as => "logout"

  root :to =>"public#index"

  match 'HFA/:id/' => 'public#show'
  match 'HFA/:id/:uid' =>'public#show'
  match 'public/projectview/:projectid/' => 'public#projectview'
  map.connect ':controller/:action/:id.:format'
  map.connect ':controller/:action/:id'

  resources :users
  resources :usertypes
  resources :user_sessions
end

Answers


The default is /controller/:id/edit, following the REST architecture.

Do you really want to change this?

If so, verify the order of the declarations:

Rails routes are matched in the order they are specified, so if you have a resources :photos above a get 'photos/poll' the show action’s route for the resources line will be matched before the get line. To fix this, move the get line above the resources line so that it is matched first.

http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions

and check your availables routes with the rake routes command:

http://guides.rubyonrails.org/routing.html#inspecting-and-testing-routes


if you put match instead of 'get' you will get all http (GET, POST, PUT, DELETE) route verbs

 get 'password_resets/:id/edit', to: 'password_reset#create', as: :send_password_reset

the 'to:' defines the controller method, 'as:' defines the path name, 'get' defines the route verb and ':id' is the token created by this line in app/views/user_mailer/password_reset.text.erb

<%= send_password_reset_url(@user.password_reset_token) %>

run "rake routes" command and check the routes for "password_resets/edit/4RghIKJNygEDswIuuCo".


Need Your Help

Need to create a flag based off of a date column and today's date

excel datetime excel-formula excel-2010 worksheet-function

I have a spreadsheet with random dates in column A. I want to create a flag (Y) for anything that is >= 3 days from today's date. To get a little more complicated, I would like to add another lev...

ffplay displays runtime error, yet still plays file

python python-2.7 ffmpeg pydub

Im Working with pydub, and I'm using ffplay. For some reason, when the program runs i get this 'error':