选择和引导的麻烦

时间:2013-11-23 23:21:13

标签: javascript ruby-on-rails twitter-bootstrap jquery-chosen

我正在尝试实现基于Railscasts剧集的视觉标签:http://railscasts.com/episodes/258-token-fields-revised

由于某些原因,找不到所选的库(请参阅以下javascript控制台中的错误)。我也有点担心所有这些引导错误。

的application.js

//= require bootstrap
//= require jquery
//= require chosen-jquery
//= require jquery_ujs
//= require_tree .

application.css

*= require_self
*= require chosen
*= require_tree .

sentences.js.coffee

jQuery ->
    $('#sentence_tag_list').chosen()

来自编辑/表单视图

<div class="sentence">
  <%= f.label :tag_list, "Tags (separated by commas)" %><br />
  <%= f.text_field :tag_list, label: false, :input_html => {multiple: true}  %>
</div> 

的Gemfile:

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
  gem "bootstrap-sass", ">= 2.3.0.0"
  gem 'jquery-rails'
  gem 'font_awesome_rails'
  gem 'chosen-rails'  # for tag formatting
end

来自javascript控制台的错误消息:

Uncaught TypeError: undefined is not a function bootstrap-transition.js:30
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-affix.js:72
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-alert.js:72
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-button.js:68
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-carousel.js:159
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-collapse.js:127
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-dropdown.js:138
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-modal.js:199
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-scrollspy.js:125
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-tab.js:114
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-tooltip.js:327
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-popover.js:38
Uncaught TypeError: Cannot read property 'fn' of undefined bootstrap-typeahead.js:295
Uncaught TypeError: Object [object Object] has no method 'chosen' sentences.js?body=1:3
event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

修改

其他信息:我刚刚在渲染页面源中注意到两个指向所选库的链接。

<script src="/assets/chosen.jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/chosen-jquery.js?body=1" type="text/javascript"></script>

当我点击第一个时,我看到了一个javascript库。第二个链接只返回一个空白页面。

编辑2

我设法通过在jquery之后移动 require bootstrap 来删除引导程序错误,但仍然得到所选错误。

//= require jquery
//= require jquery_ujs
//= require chosen-jquery
//= require bootstrap
//= require_tree .

**编辑3 **

相关问题:chosen-rails error chosen is not a function

1 个答案:

答案 0 :(得分:1)

<强>解决

经过大量搜索和修改代码后,我更改了 config / environments / development.rb

中的静态资产指令
config.serve_static_assets = false