带有 :remote=>true 的 rails3 块中的 link_to 的语法,包括 :class 和 :id [英] Syntax for link_to with block in rails3 with :remote=>true and including :class and :id

查看:31
本文介绍了带有 :remote=>true 的 rails3 块中的 link_to 的语法,包括 :class 和 :id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看在上帝的份上,我已经为此纠结了好几个小时.使用 rails3 rc,1.9.2.

For the love of god, I've been banging my head on this for hours. Using rails3 rc, 1.9.2.

我正在尝试创建一个 link_to 来提交一个带有参数、类和 ID 的 ajax 请求,并且需要一个块,以便我可以在名称周围插入一个 span 标记.文档绝对是零帮助,许多谷歌搜索也是如此.这是我到目前为止所得到的:

I'm trying to create a link_to that submits an ajax request, with parameters, a class and id, and needs a block so I can insert a span tag around the name. Documentation is of absolutely zero help, as are numerous google searches. Here's what I've got so far:

<%= link_to(
      :url=>{
        :controller => 'themes', :action => 'remove_tag',
        :entity_id => entity_id, :theme_id => theme_id,
        :entity => entity, :element_id => element_id, :parent_id=>parent_id
      },
      :remote => true,
      :id => "theme-tag-#{entity}-#{entity_id}",
      :class => "tag")  do %>
  <span class='subtract'><%= tag %></span>
<% end %>

生成的网址如下所示:

<a href="/explore/index/theme-tag-user-3?url[controller]=themes&amp;url[action]=remove_tag&amp;url[entity_id]=3&amp;url[theme_id]=16&amp;url[entity]=user&amp;url[element_id]=filter-contributor-3&amp;url[parent_id]=filter-contributors&amp;remote=true&amp;class=tag">

测试描述符

我无法正确指出文本测试描述符"实际上已正确包含在跨度内;代码格式在这里有点失败,但是,href 是错误的,没有类或 id,并且它继续下坡

I can't indicate properly that the text "Test descriptor" is actually properly included within the span; code formatting is failing a little here, however, the href is wrong, there's no class or id, and downhill it continues to roll

如果我不需要块,我可以只添加名称,而不必指定 :url=>{...} (如果关闭会引发块异常,请看图)然后按照那个:remote=>true, :id=>"whatever", :class=>"blah" 就可以了.我究竟做错了什么?因为我一般不熟悉 Rails,所以我还想了解为什么这种语法必须有如此大的不同?我的意思是真的,感谢上帝,您不必在网络应用程序中编写大量这样的链接......;-)

If I didn't need the block, I could just add the name and not have to specify :url=>{...} (leaving if off throws an exception with the block, go figure) and then follow that with :remote=>true, :id=>"whatever", :class=>"blah" and it works. What am I doing wrong? Because I'm new to rails in general, I'd also like to understand why this syntax must differ so much? I mean really, thank god you don't have to write a lot of links like this in a web app... ;-)

提前致谢

推荐答案

原来你必须做 url_for(...) 而不是 :url=>{...} 并且一切都按预期工作.

turns out you have to do url_for(...) instead of :url=>{...} and it all worked as expected.

这篇关于带有 :remote=>true 的 rails3 块中的 link_to 的语法,包括 :class 和 :id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆