0
我回到Rails(已經有幾年了),所以我很確定我只是缺少一些簡單的東西。這也可能是我對JavaScript如何在Rails中工作的理解。路由/資產管道問題 - 未定義的JavaScript方法
我想我有我的看法(在哈姆)設置正確。我已將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 = "https://stackoverflow.com/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"
其中「用戶「是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() }
感謝