Estoy tratando de implementar un enlace cuando, al hacer clic, te marca como presente en una reunión. Este enlace es un método en un ayudante:
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
El problema es que cuando represento el enlace en mi vista, algunos de los html se escapan haciendo que el enlace no funcione.
Que creo que no es una url válida. Me pregunto por qué sucede esto: llamo a html escape en la cadena completa y de carga.
Saludos
Ya que está pasando el html de un ayudante, Rails lo desinfecta para protegerlo de XSS. Puedes anularlo volviendo:
link_to_remote_registration.html_safe
http://railscasts.com/episodes/204-xss-protection-in-rails-3
También puede usar raw () en lugar de deshabilitar XSS en todo el sistema.
raw(image_tag(up_image , :id => 'will_not_attend_event_'+ event_id.to_s , border => 0))