2016-08-31 12 views
1

link_to blockを追加する必要がありますが、いくつかの問題が発生しました。ここでRails js.erb append block link_to

は、それが正常に動作し、HTMLに完全に表示しますが、私は追加するjs.erbを使用する場合、それは誤って表示していましたlink_to block

<%=link_to user_create_question_sort_section_path, :remote=> true , :method=> :post do %> 
    <button class="btn glyphicon glyphicon-sort-by-attributes"></button> 
<% end %> 

です。私は

$('#sort_btn').append("<%= j link_to user_create_question_sort_section_path, :remote=> true , :method=> :post do %><button class="btn glyphicon glyphicon-sort-by-attributes"></button><% end %>"); 

を入力js.erb

しかし、それは名前としてpath引数を取ったようで、この

enter image description here

のように表示されます。

+0

は、あなただけのパスを与えるのではなく、ビューをレンダリングする必要がリンクをレンダリング –

答えて

1

link_toブロックを部分的にラップし、js.erbテンプレートでレンダリングします。

# _link.html.erb 

<%= link_to user_create_question_sort_section_path, :remote=> true, :method=> :post do %> 
    <button class="btn glyphicon glyphicon-sort-by-attributes"></button> 
<% end %> 

そして、あなたのテンプレートで

# action.js.erb 

$('#sort_btn').append("<%= render 'link' %>");