Reputation: 75
hello everyone i have a view _disqus.html.erb when i call that view i pass an object like this
render "disqus", product: product || render "disqus", product: post
and i wanna concatenate something like this
"#{product+"_path(product)""
because sometimes i send a post and sometimes i send a product and i dont wanna make other view for the posts so i just wanna concatenate the object.
code:
var disqus_config = function () {
this.callbacks.onNewComment = [
function() {
$.ajax({
method: "PATCH",
url: '<%= product_path(product) %>',
data: {increment: "comment_count"}
})
}
];
};
url: '<%= product_path(product) %>'
how can i concatenate ? thanks
in java would be something like this
product+"_path(product)"
"product would be = post or = product"
i tried with this
url: '<%= product+_path(product) %>'
but i get syntax error :(
Upvotes: 0
Views: 1103
Reputation: 5664
In general product_path
it's just a method. You can use metaprogramming for call method when you have a name as a string:
<%= send("#{product.class.name.downcase}_path", product) %>
Hope it helps
Upvotes: 1