ruby on rails - Action 'index' could not be found for <x>Controller -
so have created rails 4.1.2 project controller, login_controller.rb , view login.html.erb. have edited routes.rb , removed put in route rails after creating controller , added default match route :controller(/:action(/:id))', :via => :get
when run server using rails s , open localhost:3000/login gives me error:
the action 'index' not found logincontroller i not know why looking action named 'index'. if right default action taken rails without specifying 1 'index' tried change url , requested this:
localhost:3000/login/login which gave me error:
no route matches [get] "/login/login" how can fix issue? thanks.
here's rake routes outputs:
prefix verb uri pattern controller#action /:controller(/:action:(/:id))(.:format) :controller#:action
say have model user , controller userscontroller. in routes.rb file, list resources , routes match based on controller actions. default, resource includes :index, :show, :new, :edit, :create, :update, :destroy. can specify want (or not) doing:
# config/routes.rb # blacklisting - these not in controller resource :users, exclude: [:show, :destroy], via: [:get, :post] # whitelisting - these in controller resource :users, only: [:index], via: [:get, :post] to understanding, filename of view (unless rendered or asset) corresponds controller action. view login page named index.html.(erb|haml)?if so, should define index def index; end. however, suggest include redirects user home or login page, depending whether logged in.
from there, real magic happens in controller define method login. here, check incoming parameters , log user in if correct. think of similar #update action.
similar how define actions include in routes, can make own custom ones. note: order of routes matter. not 100% on concept myself, suggest in case:
#config/routes.rb resource :login, only: [:index], via: [:get, :post] match '/login/login' => 'login#login', via: [:get, :post] you can use match link /login/index #login method. view called index still. , because there route it, not need view login action -- parses parameters, while index show error messages.
Comments
Post a Comment