我是怎么在这个教程做的不对:https://github.com/grosser/simple_auto_complete自动完成Rails的它不工作
这里是我的脚本的方式:
首先,我把这个在我的users_controller.rb
autocomplete_for :user, :username, :limit => 15, :order => 'created_at DESC'
在我的routes.rb
namespace :profile do
resources :users, :only => [:index] do
collection do
post "search"
get "autocomplete_for_user_name"
end
end
在我的application.js
//= require jquery
//= require jquery_ujs
//= require_tree .
//= require jquery.autocomplete.js
//= require jquery.js
jQuery(function($){//on document ready
//autocomplete
$('input.autocomplete').each(function(){
var input = $(this);
input.autocomplete(input.attr('data-autocomplete-url'),{
matchContains:1,//also match inside of strings when caching
// mustMatch:1,//allow only values from the list
// selectFirst:1,//select the first item on tab/enter
removeInitialValue:0//when first applying $.autocomplete
});
});
});
在我的意见(应用程序/视图/资料/消息/ compose.html.haml)
%div#page-info
%span#title
Compose
%span#desc
Compose a new Message
= form_for :message, :url => send_message_profile_messages_path do |message|
%label{:for => "friend"} To:
%br
=message.text_field :auto_user_name , :class => 'autocomplete', 'data-autocomplete-url'=> autocomplete_for_user_name_profile_users_path
%script{:type => "text/javascript"}jQuery(function($){//on document ready $('input.autocomplete').each(function(){var $input = $(this);$input.autocomplete($input.attr('data-autocomplete-url'));});});
//= collection_select(:message, :friend_id, @friends, :id, :username)
%br
%label{:for => "message"} Body:
%br
= message.text_area :message
%br
= message.file_field :attachment
%br
= submit_tag "Send", :confirm => "Are you sure?"
我想用自己的用户名自动填充用户(S )
注:我也安装了宝石,我认为这没有问题。
我在做什么错了?
你得到的萤火控制台任何JavaScript错误的伟大工程? – PradeepKumar 2012-08-14 08:11:19
你有没有加过javascript的叫 – PriteshJ 2012-08-14 08:26:16
你叫什么意思javascript @PriteshJ – user1559755 2012-08-14 08:35:39