如何像 haml 一样在“.erb”中连接
How to concatenate in ".erb" like haml
大家好,我有一个视图 _disqus.html.erb 当我调用那个视图时,我传递了一个这样的对象
render "disqus", product: product ||
render "disqus", product: post
我想连接这样的东西
"#{product+"_path(product)""
因为有时我会发送一个 post,有时我会发送一个产品,但我不想为 post 制作其他视图,所以我只想连接对象。
代码:
var disqus_config = function () {
this.callbacks.onNewComment = [
function() {
$.ajax({
method: "PATCH",
url: '<%= product_path(product) %>',
data: {increment: "comment_count"}
})
}
];
};
url: '<%= product_path(product) %>'
如何连接?谢谢
在 java 中会是这样的
product+"_path(product)"
"product would be = post or = product"
我试过这个
url: '<%= product+_path(product) %>'
但我收到语法错误:(
总的来说product_path
这只是一种方法。当名称为字符串时,您可以使用元编程调用方法:
<%= send("#{product.class.name.downcase}_path", product) %>
希望对您有所帮助
大家好,我有一个视图 _disqus.html.erb 当我调用那个视图时,我传递了一个这样的对象
render "disqus", product: product || render "disqus", product: post
我想连接这样的东西
"#{product+"_path(product)""
因为有时我会发送一个 post,有时我会发送一个产品,但我不想为 post 制作其他视图,所以我只想连接对象。
代码:
var disqus_config = function () {
this.callbacks.onNewComment = [
function() {
$.ajax({
method: "PATCH",
url: '<%= product_path(product) %>',
data: {increment: "comment_count"}
})
}
];
};
url: '<%= product_path(product) %>'
如何连接?谢谢
在 java 中会是这样的
product+"_path(product)"
"product would be = post or = product"
我试过这个
url: '<%= product+_path(product) %>'
但我收到语法错误:(
总的来说product_path
这只是一种方法。当名称为字符串时,您可以使用元编程调用方法:
<%= send("#{product.class.name.downcase}_path", product) %>
希望对您有所帮助