Reputation: 14504
I get a this eror when visit the url http://localhost:3000/admin/login: ActionController::RoutingError in Admin/login#index
/app/views/admin/login/index.rhtml where line #18 raised:
No route matches {:action=>"login_in_user", :controller=>"admin/login"}
Extracted source (around line #18):
15:
16: <h2>Login</h2>
17: <div class="spacer"> </div>
18: <%= form_tag(:action => "login_in_user") %>
19:
20:
21: <p>
Here is my Admin login controller class in controllers/admin:
class Admin::LoginController < ApplicationController
My route file:
namespace :admin do
resources :login
end
match ':controller/service.wsdl', :action => 'wsdl'
# Install the default route as the lowest priority.
match ':controller/:action/:id'
I do have a action named: login_in_user
UPDATE OLD ROUTE FILE:
map.connect ':controller/service.wsdl', :action => 'wsdl'
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'
Upvotes: 0
Views: 1868
Reputation:
The problem is that you don't have any mapping for the url you're trying to create a link to. login_in_user
is not one of the standard resource actions, so you need to add it explicitly. The relevant routes.rb
entry in your case currently looks like this:
namespace :admin do
resources :login
# and other stuff...
end
It could work if you did something like this:
namespace :admin do
resources :login do
collection do
post :login_in_user
end
end
However, remember that resources are not a good fit for all controllers. Creating a resources
entry generates routes that map to seven specific actions, suitable for managing a resource. A "LoginController" with an action called "login_in_user" doesn't sound like a resource to me. It's possible you're simply trying to create a controller with specific paths to log in through different means. In that case, maybe you could create the routes like so:
namespace :admin do
post 'login/login_in_user' => 'login#login_in_user'
post 'login/login_in_some_other_way' => 'login#login_in_some_other_way'
# ...
end
Some of your other routes seem a bit off to me as well. If you haven't already, I'd highly recommend reading this rails guide: http://guides.rubyonrails.org/routing.html.
EDIT:
One thing I should explain just in case is that rails won't allow access to your controller's actions automatically. You always need to have an entry in the routes file for every url the user would need to access. In your case, you have a simple catch-all rule at the bottom that looks like this:
# Install the default route as the lowest priority.
match ':controller/:action/:id'
This is not recommended anymore, since it gives needless access to too many actions and no restrictions on the access method (GET, POST, etc.). Even so, if you want to install a catch-all route to your admin interface, you could do the same in your :admin
namespace:
namespace :admin do
match ':controller/:action/:id'
end
This should solve your problem in this case, but again, it's generally not a good idea. I'm under the impression that you're dealing with legacy code, so it may be a reasonable temporary fix, but I'd still create all the necessary routes by hand first and then think about how to rewrite the controllers to work sensibly with resources. As I noted above, for your problem, this should do the trick:
namespace :admin do
post 'login/login_in_user' => 'login#login_in_user'
end
Upvotes: 1