0

我现在正在尝试使用我的 javascript 在单击元素时使用此代码呈现新视图;

$(document).ready(function() {
    $('.link-panel').click( function() {
        window.location.replace('/quotes/'+gon.gon_quote_id);
    });
});

我收到以下错误:

Couldn't find Quote with 'id'=undefined [WHERE "quotes"."user_id" = $1]

报价控制器.rb:

  def show
    @quote = current_user.quotes.find(params[:id])
    gon.gon_quote_id = @quote.id
  end

def index
@quotes = current_user.quotes.all
# how to pass the individual quote object's id to gon here

结尾

我认为这一定是我将 url 参数赋予replace方法的方式,你能帮我解决我做错了什么吗?

gon如警报测试所示,设置工作正常。)

谢谢

4

2 回答 2

0

您应该使用idURL 中的参数:

window.location.replace('/quotes/?id=' + gon.gon_quote_id);
于 2017-06-07T19:48:59.477 回答
0

该脚本不知道它是为了从 rails 访问变量,您必须这样做:

$(document).ready(function() {
    $('.link-panel').click( function() {
        window.location.replace('/quotes/'+<%= gon.gon_quote_id %>);
    });
});
于 2017-06-08T12:24:06.880 回答