2016-08-31 2 views
1

link_to block을 추가해야하지만 몇 가지 문제가 발생했습니다. 여기레일 js.erb 블록 추가 link_to

그것은 완벽하게 HTML의 벌금과 디스플레이를 작동 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 %> 

이지만, 내가 추가 할 js.erb을 사용하는 경우는 잘못 표시됩니다. js.erb에서

내가 그러나

$('#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 %>"); 

를 입력, 그것은 이름으로 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' %>");