开发者

Why is this HTML code being rendered as one giant string instead of the code being evaluated?

This code in a partial:

<div class ="vote_updated">
    <p><%= event.actor %> <% case event.subject.value
        when 1
   开发者_开发百科         puts " upvoted"
        when -1
            puts " downvoted"
        when 0
            puts " removed a vote from"  
        end %> a song. </p>
    <div class="video_div">
        <%= render 'videos/video', :video => event.secondary_subject %>
    </div>
</div>

is being rendered as one big string instead of the resulting HTML code from the embedded ruby being evaluated.

This is the code that renders the partial:

<div id="feed_div">
    <%= render_timeline current_user.recent_events %>
</div>

and this is the render_timeline method in application_helper.rb:

def timeline(events)
  events.map do |event|
    render(:partial => "timeline_events/#{event.event_type}", :locals => {:event => event})
 end.join
end


It might be that your call to .join in timeline is marking the string as unsafe - maybe try altering it to:

def timeline(events)
  events.map do |event|
    render(:partial => "timeline_events/#{event.event_type}", :locals => {:event => event})
 end.join.html_safe
end

and see if that helps :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜