路由/资产管道问题 - 未定义的javascript方法

时间:2012-10-19 03:40:13

标签: javascript ruby-on-rails ruby-on-rails-3 slideshow asset-pipeline

我要回到Rails(已经有几年了),所以我很确定我只是错过了一些简单的东西。这也可能是我对Rails中javascript的工作方式缺乏了解。

我认为我的观点(以haml为单位)设置正确。我已将javascript添加到我确定包含在布局中的文件中。 (并且css看起来正确。)我只是没有获得连接到视图的javascript函数(我在网上找到的幻灯片)。我正在尝试使用%body{ :onload => setUpslideShow() }

以下是我的观点:

%body{ :onload => setUpSlideShow() }

%script{type: 'text/javascript'}
  if ( ! window.CMFmainmenu ) { CMFmainmenu = {}; }
  var s                   = CMFmainmenu;
  s.user_id               = "#{@user.id.to_s}";
  s.partial_mainmenu_path = "/users/" + s.user_id + "/xx/mainmenu";
  s.add_new_senior        = "#{UsersController::ADD_NEW_SENIOR}"
  s.add_new_senior_path   = "#{new_seniors_settings_path(@locale,@user,@senior)}"

#mainmenu

... (edited out to save space) ...

 #slideshow.greenBorder
        #slides
          = image_tag '/assets/newlook/div_1_img.png', class: 'slide'
          %p
            Everyone loves photo albums.
            Get your user ready to brag, and
            populate and arrange albums by
            event, special people, year or any
            category you can imagine.
            =link_to "Learn how.", ''
          = image_tag '/assets/newlook/div_2_img.png', class: 'slide'
          %p
            If typing is difficult for your
            loved one, remove the frustration
            of a typed response. They can
            respond with a voice message, or
            with auto replies that you set up.
            =link_to "Learn how.", ''
          = image_tag '/assets/newlook/div_3_img.png', class: 'slide'
          %p
            Arms too short? You can specify
            the minimum font size used for
            your user's email.
            =link_to "Learn how.", ''
        #slides-controls
          1
          2
          3

这是我的javascript:

if (! window.CMFuser) { CMFuser = {}; }

$(function() {

    var s = CMFuser;

... (edited out to save space) ...

       // slideshow

       slidePrefix            = "slide-";
       slideControlPrefix     = "slide-control-";
       slideHighlightClass    = "highlight";
       slidesContainerID      = "slides";
       slidesControlsID       = "slides-controls";

       setUpSlideShow =  function()
       {
... lots of code that doesn't get called so I'm leaving it out to save space ...

以下是我认为布局中的相关行:= javascript_include_tag "lib/modernizr-2.0.6.min", "lib/respond.min","application", "users"其中“users”是javascript文件。当我注释掉%body{ :onload => setUpslideShow() }时,javascript文件会显示在html源代码中。

错误的全文:

NoMethodError in Users#mainmenu

Showing /opt/cmf/app/views/users/mainmenu.html.haml where line #4 raised:

undefined method `setUpSlideShow' for #<#<Class:0x007fe054fa0a28>:0x007fe05594ae20>
Extracted source (around line #4):

2: - # users/mainmenu
3: 
4: %body{ :onload => setUpSlideShow() }

由于

1 个答案:

答案 0 :(得分:0)

:onload的值不应该是字符串吗?

%body{ :onload => 'setUpSlideShow()' }

你确实想要制作这个HTML,对吗?

<body onload="setUpSideShow()">