0
votes

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'
2
Please post your routes.rb, at least the relevant parts of ittagCincy
Realize that the error message is the best advice you have so far. Somewhere, something is linking to "show." Having your index.html.erb file is not so relevant to the error. I agree, post your routes.rb file, we need more data to help you.aaron-coding
Do you have a users resource defined in routes before this?Dave Newton
You should post your entire routes.rb file. We cannot see if other routes are defined above your users#index definition. Because the order changes the game on the routes table.turhanco

2 Answers

1
votes

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'.

0
votes

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)