gpt4 book ai didi

javascript - 当我在 application.js.erb 中使用 <%= home_index_path %> 时未定义局部变量或方法,为什么?

转载 作者:行者123 更新时间:2023-11-28 02:14:23 25 4
gpt4 key购买 nike

如标题所述,我有一个 application.js.erb 文件,如下所示:

//= require jquery
//= require jquery-ui
//= require bootstrap
//= require html5shiv
//= require_tree .

$(document).ready(function(){

$("#opening-first").fadeIn(1000, function() {
$("#opening-second").fadeIn(1000, function() {
$("#opening-container").delay(500).fadeOut(1000, function() {
$("#body-overlay").fadeOut(1000);
});
});
});

$(".me").on('click', function(){
fadeAndReload('<%= me_home_index_path %>');
});

$(".home").on('click', function(){
fadeAndReload('<%= root_path %>');
});

function fadeAndReload(fileName) {
var body = $("#reload-me");
body.fadeOut(500, function() {
body.load(fileName, function() {
body.fadeIn(500);
});
});
}
});

我的路线列出为:

   home_index GET /home/index(.:format) home#index
me_home_index GET /home/me(.:format) home#me
root / home#index

我收到以下错误:

undefined local variable or method `me_home_index_path' for #<#<Class:0x007f99d63b5728>:0x007f99d65ef9d0>
(in /Users/[filepathhere]/javascripts/application.js.erb)

问题是什么?

最佳答案

无论如何,我必须将此行添加到我的 require 语句下的 application.js.erb 文件的顶部,现在一切正常:

<% environment.context_class.instance_eval { include Rails.application.routes.url_
helpers } %>

关于javascript - 当我在 application.js.erb 中使用 <%= home_index_path %> 时未定义局部变量或方法,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16626146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com