请帮助解决问题。
我使用rails 5.我创建了简单的网站,它跟随导航:
kalinin@kalinin ~/rails/test5 $ rails routes
Prefix Verb URI Pattern Controller#Action
pages_home GET /pages/home(.:format) pages#home
pages_about GET /pages/about(.:format) pages#about
pages_portfolio GET /pages/portfolio(.:format) pages#portfolio
pages_blog GET /pages/blog(.:format) pages#blog
pages_contact GET /pages/contact(.:format) pages#contact
root GET / pages#home
主页有两条路径:
http://localhost:3000/pages/home
http://localhost:3000/
主页有js-slider。初始化代码:
function clearText(field)
{
if (field.defaultValue == field.value) field.value = '';
else if (field.value == '') field.value = field.defaultValue;
}
var flashvars = {};
flashvars.xml_file = "photo_list.xml";
var params = {};
params.wmode = "transparent";
var attributes = {};
attributes.id = "slider";
swfobject.embedSWF("flash_slider.swf", "flash_grid_slider", "960", "350", "9.0.0", false, flashvars, params, attributes);
ddsmoothmenu.init({
mainmenuid: "templatemo_menu", //menu DIV id
orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
classname: 'ddsmoothmenu', //class added to menu's outer DIV
//customtheme: ["#1c5a80", "#18374a"],
contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
})
问题:
在路径上http://localhost:3000/pages/home
此滑块不显示。控制台输出跟随错误消息:
获取http://localhost:3000/pages/photo_list.xml 404(未找到)
但在路径http://localhost:3000/
滑块显示没有问题。
PS:
路径pages/photo_list.xml
不存在。但路径public/photo_list.xml
已存在。
的PageController:
class PagesController < ApplicationController
def home
render layout: "home"
end
def about
end
def portfolio
render layout: "portfolio"
end
def blog
end
def contact
end
end
答案 0 :(得分:0)
这是因为这一行:
flashvars.xml_file = "photo_list.xml";
这将与您所在的页面相关。因此,当您在http://localhost:3000/pages/home
时,它会尝试加载http://localhost:3000/pages/photo_list.xml
。当您在主页上时,它将加载正确的文件。
将该行更改为:
flashvars.xml_file = "/photo_list.xml";