Ruby on rails :with子句防止在链接到远程调用中执行操作

Ruby on rails :with子句防止在链接到远程调用中执行操作,ruby-on-rails,ajax,haml,Ruby On Rails,Ajax,Haml,以下代码中的:with子句出现问题 -counter.times do |c| -elem = @tags[c] #{elem.name}#{link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart'}, :with => "'tag_remove=' + #{elem}"} 如果我取出:with子句,那么当我单

以下代码中的:with子句出现问题

-counter.times do |c|
  -elem = @tags[c]
  #{elem.name}#{link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart'}, :with => "'tag_remove=' + #{elem}"}
如果我取出
:with
子句,那么当我单击图像链接时,就会执行
从购物车中删除标签。但是,我不能用
elem
做任何事情,因为它不会以任何方式从购物车中移除标签

如果我将
:和
子句放在那里,那么
从购物车中删除标签
根本不会执行

根据我的理解,:with应该使我能够在
从购物车中删除标签中执行此操作

def remove_tag_from_cart
  puts params[:tag_remove].name
end
同样,如果我包含:with子句,则此方法不会运行

我只想将
elem
elem.id
传递到
从购物车中移除标签,这样我就可以使用它(查找东西等)。这是最好的/正确的方法吗?如果没有,我的选择是什么?

用于跟踪ajax调用、查看生成的html等

:with
选项为(从):

指定 XMLHttpRequest的参数。任何 表达式应返回有效的URL 查询字符串

例如:

:with=>“'name='+$('name')。value”

您正在执行
:使用=>“'tag_remove='+{elem}”

elem似乎是ActiveRecord对象,所以您真正想要做的似乎是用参数传递它的id。但是您可以使用普通的url参数,而不必使用javascript的
:with

link_to_remote image_tag('x.png'), :url => {:controller => 'questions', :action => 'remove_tag_from_cart', :tag_remove_id => elem.id}
在使用中

Tag.find(params[:tag_remove_id])

请发布您生成的html是什么?您想要什么?好吧,这段代码存在于另一个Ajax调用呈现的部分中,因此我不知道如何查看生成的html。问题如我所述:{elem.name}{link_to_remote image_tag('x.png'),:url=>{controller=>'questions',:action=>'remove_tag_from_cart'},:with=>“'tag_remove='+{elem}包含:with子句,不执行remove_tag_from_cart方法。当我删除:with子句时——也就是说,当它只是{elem.name}{link_to_remote image_标记('x.png'),:url=>{:controller=>'questions',:action=>'remove_tag u from_cart'}时,正确执行remove_tag u from_cart。