Rails将局部变量传递给escape_javascript

时间:2018-10-07 03:45:38

标签: ruby-on-rails ruby

我想像这样将本地变量传递给escape_javascript

function renderPartial(partial) {
          $('body').append('<%=escape_javascript render(:partial => partial) %>');
}

但是我得到一个错误:#<#:0x00007f9be09a36b0>的未定义局部变量或方法“ partial”

所以我的问题是,如何在这种情况下传递局部变量。

2 个答案:

答案 0 :(得分:1)

<% %>括号中的代码由服务器端的ERB预处理程序执行。这是Ruby代码。如我所见,您的变量partial是JS函数的一个参数,它将在客户端运行。因此,这两个变量来自不同领域。并且未定义本地Ruby变量partial

请说明您要使用此代码实现的目标?

答案 1 :(得分:0)

您能只更改enter code here password = 'Gain access' count = 0 input = input("Enter the password: \n") while input != password: print("Incorrect password! Please try again: \n") count = count + 1 print("You have now got your password wrong " + str(count) + " times. \n") if(count < 5): print("Access denied, please contact security to reset your password.") break else: print("Accepted, welcome back.") print("You had " + str(count) + " attempts until you got your password right.") 变量名吗,我认为partial是rails中的保留关键字。