2013-04-25 151 views
3

我正在尝试将我的link_to标记转换为link_to do块,如讨论here。我不确定:remote => true选项应该在哪里。Rails link_to用remote => block做block?

原文:

<%= link_to "Title", {:controller => "users", :action => "edit", :id => u.id }, :remote => true %> 

到目前为止,这是工作的link_to do块,但我不知道往哪里放:远程=>真。它在选项块或html_options中不起作用。

<%= link_to (options = {:controller => "users", :action => "edit", :id => u.id}) do %> 
    Link contents 
<% end %> 

回答

6

没有测试过,但我认为正确的方法是

<%= link_to (url_for({:controller => "users", :action => "edit", :id => u.id}), :remote => true) do %> 
    Link contents 
<% end %> 
+0

你指出我在正确的方向!原来你关闭了url_for before:remote => true。谢谢,我会更新与什么对我有效的问题:) – user1436111 2013-04-25 02:46:55

+0

@ user1436111相反,创建一个答案。答案不属于问题。另外,在':remote'之前关闭'url_for' * *。 – 2013-04-25 02:51:48

4

明白了!正确的语法是

<%= link_to (url_for({:controller => "users", :action => "edit", :id => u.id})), :remote => true do %> 
    Link contents 
<% end %> 

谢谢。