回答

1

其實,你使用的寶石不夠好。你應該使用jquery-rails。 安裝如下

gem install jquery-rails 

或將其添加到您的Gemfile

gem 'jquery-rails' 

,然後做

rails g jquery:install 

這不僅消除了prototype.js中,並下載jQuery的,但也(重要的是!)下載適用於jQuery的rails.js,並確保所有標準的rails-helpers將繼續工作。

1

你需要後原型加載jQuery的,然後調用jQuery.noConflict(),例如:

$j = jQuery.noConflict(); 

然後使用$j的jQuery,而不是$

或者說,她一直在叫jQuery.noConflict(),您可以使用$函數裏面只是,例如:

jQuery.noConflict(); 
//$ is prototype 
(function($) { 
    //$ is jQuery 
})(jQuery); 
//$ is prototype 

或者說你做一個document.ready處理,短版本是:

jQuery.noConflict(); 
//$ is prototype 
jQuery(function($) { 
    //$ is jQuery, this runs when the DOM is ready 
}); 
//$ is prototype 
0

Rails 3助手也應該使用jQuery。 (東西像link_to ..., :remote => true),唯一要做的就是加載jQuery和新的rails.js。

我猜想例外是RJS相關的助手。

Nick Craver的技巧將使jQuery和原型一起工作。