I'm trying to write a small jQuery method that works on my rails site and check if a username is开发者_JS百科 available. This is all handled in the users_controller.rb and on the form:
<script>
$( function() {
$('input#username').keyup( function() {
var username = $('input#username').val();
url = '/users/check_username/';
params = { username : username };
$.get(url, params, function(response){ markUsername(response); }, "json");
});
})
</script>
The markUsername() function simply inserts text into some span saying if the username is available or taken.
I have server-side code inside the users_controller that checks if the username is taken or free, but when I actually test it out I get this error:
ActionController::UnknownAction (No action responded to show. Actions: ...edit... enter code here check_username...)
So I know I have this method, I just don't know why 'show' is being called. Probably a routing issue, but I'd appreciate help on this anyhow - thanks.
The problem was in the RESTful routing rails takes by default. I changed my routes in routes.rb from
map.resources :users
to
map.connect 'users', :controller => 'users', :action => 'index'
And there was much rejoice :)
精彩评论