0

I am trying to implement an auto-complete form following this example How to set up jquery ui autocomplete in rails

When I go to http://localhost:3000/initiatives/10.json?term=Ion I get a "Wrong number of arguments 1 for 0".

In my initiatives#show I have the following code:

if params[:term]
  Error points to this line - @people = User.all(:all, :conditions => ['name LIKE ?', "#{params[:term]}%"])
else
  @people = User.all
end

respond_to do |format|  
  format.html  
  format.json { render :json => @people.to_json }
end

I am using PostgreSQL and I'm thinking the query is not made for this database.

This is the script for auto complete:

 <script type="text/javascript">
    $(function() {

    $('#delegatee').autocomplete({  
            minLength: 2,
            source: '<%= json_path %>',

            focus: function(event, ui) {
                console.log("xxxxxx");
                console.log(ui);

                $('#delegatee').val(ui.item.name);
                return false;
            },

            select: function(event, ui) {

                $('#delegatee').val(ui.item.name); 
        $('#delegatee_id').val(ui.item.id);
                return false;
            }
        })
        .data("uiAutocomplete")._renderItem = function( ul, item ) {
            return $( "<li></li>" )      
                .data( "item.autocomplete", item )

                .append( "<a>" + item.name + "</a>" )
                .appendTo( ul );
        };
    });

</script>

"<%= json_path %> " leads to /initiatives/:id.json which renders the data.. correctly I think.

When I try the form out it gives me a 500 Internal Server error in the console, which I believe is the one I described above and it points me to this line in the jquery script: xhr.send( ( options.hasContent && options.data ) || null );

I'm using Rails 4.2.0.beta4 and Ruby 2.0.0p195.

Community
  • 1
  • 1
parseb
  • 138
  • 3
  • 13

1 Answers1

0

In Rails > 4.0, ActiveRecord's .all don't take multiple parameters as you are passing, and thus the Wrong number of arguments 1 for 0 error.

The query you are trying to setup would be just:

@people = User.where('name LIKE ?', "#{params[:term]}%")

Hope it helps!

dgilperez
  • 10,716
  • 8
  • 68
  • 96