내 홈페이지에있는 js 인라인 스크립트를 Asset의 javascript 파일로 옮기고 싶습니다.하지만 변수 때문에 복잡합니다. 여기에 정보를 위해서 home.html.erb레일 4 - js 인라인 스크립트를 내부 JS 파일로 이동
<div>
this is the homepage
</div>
<script>
<% @deal.deal_details.each_with_index do |popin, index| %>
<% index_plus_one = index + 1 %>
function loadInfoPopin() {
var msg;
msg = Messenger().post({
message: '<%= j render partial: "deals/info_popin/info_popin#{ popin['popin_id'] }",
locals: { popin: popin, index: index_plus_one } %>'
});
}
<% end %>
</script>
이 거래의 열/속성 'deal_details'의 형식입니다 (그것은 JSON 속성이다) :
[{"popin_id":"4","text1":"qqq","text2":"sqsq","image1":"sqqs"},{"popin_id":"5","text1":"sqqs","video1":"s"}]
이것은 예제이며 가능한 한 많은 json 블록을 배열 안에 넣을 수 있습니다.
거래/info_popin/info_popin5.html.erb은 (는 예입니다)
<div>
<p><a href="<%= popin['image1'] %>">cool image</a></p>
</div>
</div>
이제 , 나는 (즉, 자바 스크립트 파일에 전체 스크립트 또는 적어도 기능 loadInfoPopin()를 이동하는 방법 보기 home.html.erb에서 멀리 말하는 것입니다)?
감사
감사합니다. – Mathieu