0

I am inserting the following HTML into the DOM from within in AJAX success callback. The AJAX call provides data, which contains the fields used below. For every player1 and player2 there is an associated image saved in assets/images as "#{first_name}_#{last_name}". How can I replace the data fields in the HTML below with ERB? Specifically, I would like to use rails' image_tag so that the image's url includes the alpha-numeric code (digest) that is appended to the image url in the production environment (Heroku).

Thanks!

    getFullMatchupHTML = (data) ->
        fullMatchupHtml = 
        '<div class="row">' +
            '<div id="matchupID" data-matchupid=' + data.matchup.id + '></div>' +
            '<div id="mpcontainer" class="">' +
                '<div id="mp1" class="span5 mp">' +
                    '<h3>' + data.player1.first_name + ' ' + data.player1.last_name + '</h3>' +
                    '<h4>' + data.player1OpponentTeamName + '</h4>' +
                    '<div id="mpimage1" class="mpimage">' +
                        '<img src="/assets/' + data.player1.first_name + '_' + data.player1.last_name + '.jpg" alt="' + data.player1.first_name + '_' + data.player1.last_name + '" class= "playerpic" >' +
                    '</div>' +
                '</div>' +
                '<div id="mp2" class="span5 mp">' +
                    '<h3>' + data.player2.first_name + ' ' + data.player2.last_name + '</h3>' +
                    '<h4>' + data.player2OpponentTeamName + '</h4>' +
                    '<div id="mpimage2" class="mpimage">' +
                        '<img src="/assets/' + data.player2.first_name + '_' + data.player2.last_name + '.jpg" alt="' + data.player2.first_name + '_' + data.player2.last_name + '" class= "playerpic" >' +
                    '</div>' +
                '</div>' +
            '</div>' +
        '</div>' +
        '</br>' +
        '<div class="row" id="num-votes-row" class="hiddenVoteRow">' +
            '<div class="">' +
                '<div id="mpts1" class="span5">' +
                    '<h2>' + data.ptsplayer1 + '</h2>' +
                '</div>' +
                '<div id="mpts2" class="span5">' +
                    '<h2>' + data.ptsplayer2 + '</h2>' +
                '</div>' +
            '</div>' +
        '</div>'
4

1 回答 1

1

尝试放置format.js在控制器操作的底部以响应js.erb视图。在该视图中,您可以简单地放置要在服务器响应您的 ajax 调用时运行的 javascript。因此,如果您的操作是edit例如,则edit.js.erb在适当的视图文件夹中创建一个名为的视图。

于 2013-10-15T16:17:25.320 回答