问题描述:

Whenever I try to access the index method of my user controller, I get an error from rails that says the following:

Unknown action

The action 'show' could not be found for UsersController

My routes.rb file does not have a route to show, but it does have one to index.

Even when I enter localhost:3000/users/index into my url bar, I still get the same issue.

I have been looking for an answer to this question for hours and have still had no luck.

EDIT:

I took the advice to route with get 'users/index' => 'users#index', but that did not help. The index.html.erb is in the right place. I have an index method defined in my users_controller.rb

The section of my routes.rb:

get 'users/index' => 'users#index'

get 'users/sign_up_partial'

post 'users/create'

网友答案:

You are using 'localhost:3000/users/index'. It will redirect to show. If you will do rake route you will find

/users/:id(.:format) will redirect to show action of users controller and in your case as you are using users/index its considering 'index' as user id.

For index action you just need to use URL 'localhost:3000/users'.

网友答案:

From my experience you should have in your routes.rb file:

get "users/index" => "users#index"

Have your index defined in your users_controller.rb

and

make sure you have the view file created (views/users/index.html.erb)

相关阅读:
Top