How to fix this up? " Unknown action The action 'index' could not be found for UsersController"
When开发者_开发百科 I go to my localhost:3000/users page, I get:
Unknown action The action 'index' could not be found for UsersController.If you were following Hartl's tutorial,then accessing localhost:3000/users will cause this error. Try localhost:3000/signup instead.
You need not define the default actions (assuming appropriate http method), all you need to do is add the following to your config/routes.rb
resources :users
First you need to make sure that your controller actually has an index action, so
class UsersController < ApplicationController
has to include the def index ... end
in it.
Also, make sure your routes are set up correctly using
resources :users
and check it by typing
rake routes
in the terminal to check that the routes are right.
You might also want to check that the root
is set up correctly in the config/routes.rb file
if you got the same problem with me (I cant access the localhost:3000/users but I can access my localhost:3000/signup), it might be works for u.
First, in your users_controller.rb (Controller for Users) , add
def index
end
Then , make a file "index/html/erb" in your app/views/users/index.html.erb and put this code
<% controller.redirect_to "/signup" %>
You might have to rerun your server, and it works on my problem.
Remember, if you've included
get 'signup' => 'users#new
resources :users
…in your routes.rb
file, then you need to use localhost:3000/signup instead. I believe if you removed get 'signup' => 'users#new
and left only resources :users
then using localhost:3000/users would take you to the new user signup form.
Remove the debugger
line. Also, make sure you have exit
the rails console.
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
debugger
end
def new
end
end
精彩评论