ruby-on-rails
2009-04-27 16 views 1 likes 
1

私はdrop_receiving_elementを作成したい:urlにはjavascriptが含まれている。現在、私はちょうどヘルパー関数を作成し、そのような中要素ハードコーディングされた:しかし、かなりハック醜いですjavascript in rails:urlパラメータ

def create_classification_droppable(droppable_id, classification) 
    "<script type='text/javascript'> 
    //<![CDATA[ 
     Droppables.add('#{droppable_id}', {accept:'lead', onDrop:function(element){new Ajax.Request('/leads/' + (element.id.split('_').last()) + '.js', {asynchronous:true, evalScripts:true, method:'put', parameters:'lead[classification]=#{classification}&authenticity_token=' + encodeURIComponent('#{form_authenticity_token}')})}}) 
    //]]> 
    </script>" 
end 

。 URLは、コールチェーンのさらに下にエスケープされているため、残念ながら、これは(なurl_forで、私は信じている)ことができていないようだ

drop_receiving_element('some_class',     
    :accept => 'some_other_class', 
    :url => formatted_whatever_path(SOMETHING_BASED_ON_WHATEVER_IS_BEING_DROPPED)) 

それとも

formatted_whatever_path(:id => "some_javascript", :js) 

:理想的には私のような何かをしたいと思います。代替案は何ですか?

答えて

0

使用しているレールのバージョンは? 2.3.8の場合は、 "文字列追加バグ"のために "エスケープ"が発生している可能性があります。 https://rails.lighthouseapp.com/projects/8994/tickets/4695-string-added-to-rails_helpers-gets-html-escaped

巧妙なハックを見つけて修正することができます(例: "# {my_string} "を使用して再評価するか、2.3.5にダウングレードしてください)。

関連する問題