简体   繁体   English

手动将flexslider添加到Rails 4应用中-类型错误flexslider不是功能

[英]Adding flexslider manually into Rails 4 app - Type Error flexslider is not a function

I am trying to fix an error in Rails 4 app . 我正在尝试修复Rails 4应用程序中的错误。 The flexslider on my app doesnt work , no images loading at all. 我的应用程序上的flexslider不起作用,根本没有图像加载。 In the console it shows - TypeError (..).flexslider is not a function The theme works completely fine when its not integrated in Rails . 在控制台中,它显示TypeError (..).flexslider不是函数当主题未集成到Rails中时,主题可以完全正常工作。 Its a bootstrapped based theme , with following configs - The application.css.scss file looks like the following 它是基于Bootstrapped的主题,具有以下配置-application.css.scss文件如下所示

*= require_self
*= require font-config
*= require framework_and_overrides
*= require animate
*= require flexslider
*= require site-wide

For application.js file has the following - 对于application.js文件,具有以下内容-

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require flexslider
//= require cbpAnimatedHeader
//= require jqueryeasing
//= require jquerymousewheel
//= require classie
//= require scrollpage
//= require site

Tried changing their order quite a few times , but no effect. 尝试过多次更改其顺序,但没有效果。 The sliders are initialized in the following way - 滑块以以下方式初始化-

$(document).ready(function() {
$('#myCarousel').flexslider({
        animation: "fade",
        directionNav: false,
        controlNav: false //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage

    });
    $('#slider').flexslider({
        animation: "fade",
        directionNav: true
    });
   });

I am a Rails Beginner ,please throw some insight , been trying to solve it for the last few hours . 我是Rails初学者,请投入一些见识,在过去的几个小时里一直在努力解决它。

Thanks for your time . 谢谢你的时间 。

Update : I am using RailsApps starter apps by Daniel Kehoe using composer . 更新:我正在使用composer使用Daniel Kehoe编写的RailsApps入门应用程序。

Update : I have not installed flexslider using any gem , since the gem I found on rubygems website is using an older version , ie. 更新:我没有使用任何gem安装flexslider,因为我在rubygems网站上找到的gem使用的是旧版本,即。 flexslider 2.2 and I am using 2.4 . flexslider 2.2,我正在使用2.4。

So I am trying to do it manually . 所以我想手动做。

Okay, it also took me a while to figure it out but works amazingly now. 好的,我花了一些时间才弄清楚,但现在效果惊人。

STEP 1: 第1步:

Download source code from here: http://flexslider.woothemes.com/thumbnail-controlnav.html 从此处下载源代码: http : //flexslider.woothemes.com/thumbnail-controlnav.html

STEP 2: 第2步:

Then, get three files as below: 然后,获取三个文件,如下所示:

1. /demo/css/flexslider.css
2. /fonts      //yes, copy this entire folder that contains four files
3. /demo/js/jquery.flexslider.js

STEP 3: 步骤3:

Relocate the first two files (1 and 2) inside vender/assets/stylesheets, and the last one (3) inside vender/assets/javascripts 在vender / assets / stylesheets中重新放置前两个文件(1和2),在vender / assets / javascripts中重新放置最后一个(3)

STEP 4: 第四步:

include in application.css/sass on top: 包括在application.css / sass中:

*= require flexslider

and include in application.js: 并包含在application.js中:

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.flexslider
//= require_tree .

SETP 5: SETP 5:

Place the below inside application.js 将以下内容放入application.js

$(window).load(function() {
  $('.flexslider').flexslider({
    animation: "slide"
   });
});

Then you get basic slider. 然后,您将获得基本的滑块。 If you want to get other slider types, just change the STEP 5 javascript code to whatever you see here: http://flexslider.woothemes.com/index.html 如果要获取其他滑块类型,只需将STEP 5 javascript代码更改为您在此处看到的任何内容: http : //flexslider.woothemes.com/index.html

It should be 它应该是

*= require jquery.flexslider

instead of 代替

*= require flexslider

There are two gems flex slider & flexslider-rails : both have the same way of including javascript. 有两个gem flex sliderflexslider-rails :两者具有相同的包含javascript的方式。 See the documentation for the one you are using. 请参阅您正在使用的文档。

https://github.com/constantm/Flexslider-2-Rails-Gem#usage https://github.com/werein/flexslider-rails#usage https://github.com/constantm/Flexslider-2-Rails-Gem#usage https://github.com/werein/flexslider-rails#usage

Okie , Its my first time integrating a bootstrap based theme developed outside of the rails environment and than integrated into it . Okie,这是我第一次将基于Bootstrap的主题集成到Rails环境之外,然后再集成到其中。 here's how I solved the issue In the application.js file (the manifest file) , I have added 这是我解决问题的方法在application.js文件(清单文件)中,我添加了

//= require_self on top like below : //= require_self在顶部,如下所示:

//= require_self
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require flexslider
//= require cbpAnimatedHeader
//= require jqueryeasing
//= require jquerymousewheel
//= require classie
//= require scrollpage
//= require site

Placing it anywhere in between //= require jquery and //= require turbolinks made my sliders and even bootstrap modals not working . 将其放置在//= require jquery//= require turbolinks之间的任何位置使我的滑块甚至引导模态都无法工作。 So after lot of attempts I figured out , it has to be on top. 因此,在我尝试了很多尝试之后,它必须处于最重要的位置。

How I found out , almost everytime I checked my source yesterday , I was ignoring the application-[content hash].js , which was placed below all the js files I mentioned in the manifest file . 我怎么发现的,几乎昨天我每次检查源代码时,我都忽略了application- [content hash] .js,它放在清单文件中提到的所有js文件下面。

Today , I thought may be this file is creating the issue, and since the file name was application-[content hash].js I used //= require_self to accommodate its placement hard-coded in the file itself . 今天,我认为这可能是该文件引起的问题,并且由于文件名是application- [content hash] .js,所以我使用//= require_self来容纳其在文件本身中进行硬编码的位置。 I was unaware of the //= require_self stuff for the js since I see it being mentioned only in the css manifest file,may be, its because of my journey with Rails 4.2 is just 5-6 months old . 我没有意识到js的//= require_self东西,因为我看到它仅在css清单文件中被提及,可能是因为我使用Rails 4.2的旅程才5-6个月大。 So senior rails developer's might have a better way to do it . 因此,高级Rails开发人员可能会有更好的方法。

If anyone can improve the answer or throw some more light into it , I will be grateful. 如果有人可以改善答案或提供更多启示,我将不胜感激。

Thanks ** Update - Okie here's another thing I found out , I was using a starter app by Daniel Kehoe using Composer tool and it contained precompiled assets in public folder , which got included when used the require_self directive. 感谢**更新-Okie这是我发现的另一件事,我使用的是Daniel Kehoe的启动程序,使用的是Composer工具,它在公共文件夹中包含预编译的资产,在使用require_self指令时将其包含在内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM