开发者

Rails & jQuery - getting UnknownAction error when checking username availability

开发者 https://www.devze.com 2022-12-10 11:35 出处:网络
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:

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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号