我试图实现一个链接,当点击标记你为会议present。这个链接是一个帮助器中的方法:
def link_to_remote_registration(event_id)
down_image = "down_blanco.png"
up_image = "up_blanco.png"
unless registration.nil?
if registration.present == 1
up_image = "up_filled.png"
elsif registration.present == 0
down_image = "down_filled.png"
end
end
link_to_remote_registration = String.new
loading_and_complete = "Element.show('indicator_event_"+event_id.to_s+"'); Element.hide('vote_"+event_id.to_s+"')".html_safe
complete = "Element.hide('indicator_event_"+event_id.to_s+"'); Element.show('vote_"+event_id.to_s+"')".html_safe
link_to_remote_registration =
link_to(image_tag(up_image , :id => 'will_not_attend_event_'+ event_id.to_s , border => 0),
:url => new_registration_path(:present => 1, :event_id => event_id, :escape => false),
:remote => true,
:method => :put,
:loading => loading_and_complete,
:complete => complete)
return link_to_remote_registration
end
问题是,当我在我的视图中渲染链接时,一些html得到转义,使链接不工作。
<a href="/calendar?complete=Element.hide%28%27indicator_event_1%27%29%3B+Element.show%28%27vote_1%27%29&loading=Element.show%28%27indicator_event_1%27%29%3B+Element.hide%28%27vote_1%27%29&method=put&remote=true&url=%2Fregistrations%2Fnew%3Fevent_id%3D1%26present%3D1">
<img id="will_not_attend_event_1" border="0" src="/images/up_blanco.png?1198181114" alt="Up_blanco">
</a>
我认为这不是一个有效的url。我想知道为什么会发生这种情况-我调用html转义完成和加载字符串。
对
由于您是从helper传递html,因此Rails对其进行了消毒以防止XSS。你可以通过返回
来覆盖它 link_to_remote_registration.html_safe
您也可以使用raw()而不是在系统范围内禁用XSS。
raw(image_tag(up_image , :id => 'will_not_attend_event_'+ event_id.to_s , border => 0))