2010-03-24 48 views
2

我想知道,如果:與屬性從Rails3中刪除,因爲我無法找到在Rails3中API的任何東西 - http://rails3api.s3.amazonaws.comrails3 link_to:帶屬性?

有人有線索,或者提供如何使用的提示:與參數與發送數據的link_to

非工作例如:

= link_to "Foo", {:action => "filter", :filter => "filter1",:with => "'test='+$('search').value"}, :remote => true, :class => "trash unselected", :id => "boo" 

的感謝!

回答

1

有一種方法可以解決它。

使用此視圖中作爲指導:

link_to "Foo", {:action => "filter", :filter => "filter1"}, {:remote => true, :class => "trash unselected", :id => "boo", 'data-with' => "'&test='+$('search').value"} 

(移動:與所述第二部分,並使其「 - 與數據」)

並且這添加到底:

<script type="text/javascript" charset="utf-8"> 
    $$('a[data-remote=true]').each(function(a){ 
    a.onclick = function(){a.setAttribute('href', a.getAttribute('href') + eval(a.getAttribute('data-with')))}; 
    }); 
</script> 
當然

,你將需要有原型加載(是一個Rails應用程序的默認的JavaScript)


的東西比這一個班輪更好:http://gist.github.com/451508

使用要點,你不需要啓動:與&或?

2

我今天很苦惱,過了一段時間,我想出了rails.js中的一些小技巧。在handleRemote方法我已經改變了這一點:

} else { 
    method = element.attr('data-method'); 
    url = element.attr('href'); 
    data = null; 
} 

這樣:

} else { 
    method = element.attr('data-method'); 
    url = element.attr('href'); 
    data = eval(element.attr('data-with')); 
} 

感謝對,現在我可以使用的link_to:遙控器是這樣的:

<%= link_to "link", some_path, :remote => true, 'data-with' => "'address=' + $j('#office_address').val();" %> 

注:這是隻有當你使用jquery時纔有效,但應用這個原型不應該很難。