Reputation: 565
I am writing a simple look up that checks to see if a username already exists in the database. So far things have been fairly straight forward. However I do have an issue with how I am doing my routing.
Currently in my routes.rb I have the following:
namespace :broker do
namespace :userdesk do
resources :dashboards do
end
resources :accounts do
get :validateUsername
end
end
end
When I use rake routes, I get the following route for validateUsername:
broker_userdesk_account_validateUsername GET /broker/userdesk/accounts/:account_id/validateUsername(.:format) {:action=>"validateUsername", :controller=>"broker/userdesk/accoun
ts"}
For this action, I am passing the username and not the account_id. Is there a way to modify the route so that it uses something like this:
/broker/userdesk/accounts/:username/validateUsername(.:format)
Upvotes: 0
Views: 137
Reputation: 5134
First of all this doesn't seem particularly 'Railsy' or RESTful but you could define a specific route using match
match '/broker/userdesk/accounts/:username/validateUsername' => 'broker/userdesk/accounts#validateUsername'
UPDATED
I recommend the rails guide on routing: http://guides.rubyonrails.org/routing.html.
I have ignored your namespaces in my examples.
If you are nesting within the accounts resource, you would expect to scope by an account, not a username.
It would be more RESTful to try something like /users/:id/validate
.
In fact, if all you are doing is checking if the user exists, you could hit the show action of users and handle 404s:
resources :users # would give you /users/:id where you would either return a user or a not found (400)
Upvotes: 1