私はRuby on Railsと一緒にAgile Web Development with Railsに飛び込んでいます。link_toと:method =>:inline javascriptではなくpostを使用しているときに、アンカーにイベントを追加しますか?
私はあなたが使用して一部になった:RESTfulなことしようとする試みで
<%= link_to (image_tag(product.image_url), {:action => :add_to_cart, :id => product}, :method => :post) %>
、Railsは各アンカータグにはJavaScript
今onclick="var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;var s = document.createElement('input'); s.setAttribute('type', 'hidden'); s.setAttribute('name', 'authenticity_token'); s.setAttribute('value', 'gegcVQGk3yN/q+SjZehByuyAHiqh5BSZWa4QHZb8DOU='); f.appendChild(s);f.submit();return false;"
このインラインを蹴る、私は傾いています使用しないように:メソッド=>:ポスト、そして代わりのようないくつかのプロトタイプのJS何か書く:
$$('div.entry a').observe('click', postAnchor);
function postAnchor(event) {
// create a form around the anchor
// submit the form with the right product id
}
は時間に方法はあります私のケーキを食べて食べる?使用:メソッド=>:リンク上に投稿しますが、Railsは上記のようなJSの小さなブロックを追い出しますか?
または:method =>:postを使用すると、文字化けしたgookを無視するだけで済みます。
私のpostAnchor関数でform_authenticity_token.inspectを使用できます。この次の繰り返しを見たいと思っています。 –