error saying “autocomplete method doesn't exis

2020-05-07 07:22发布

问题:

In my rails application I am trying to use rails3-jquery-autocomplete gem. I included the following line in Gemfile. 'gem rails3-jquery-autocomplete' and gave bundle install and its listed in the gems.

My controller :

class ReleasesController < AuthorizedController
  # GET /releases
  # GET /releases.xml
    autocomplete :users, :name 

     def new 
    @release = Release.new
    @ic_ids = params[:ic_ids] ? params[:ic_ids] : []
     @testers = User.find_by_sql("select * from users where id in(select user_id from user_role_assignments where role_id in (select id from roles where name like 'Tester')) order by name").paginate(:page=>params[:page],:per_page=>30)   
   if params[:project_id]
      @release.project = Project.find(params[:project_id])
    end
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @release }
          end
  end

  end

routes file:

get 'releases/autocomplete_users_name'

view file:

= autocomplete_field_tag 'tester_name', '', users_autocomplete_user_name_path, :size => 75 

I am getting the error

undefined method `autocomplete' for #<ReleasesController:0xb731e2c0>

Please help me out here.

Thanks, Ramya.

回答1:

Did you run the generator ? rails generate autocomplete:install

And within controller it should be

 Class SomeController
 autocomplete :user, :name 
   def yourmethods
   end
 end   

Please look at the instructions here : https://github.com/crowdint/rails3-jquery-autocomplete