Eliminar DIV no deseado de cualquier forma generado desde la forma de autenticidad_token

StackOverflow https://stackoverflow.com/questions/4832877

  •  27-10-2019
  •  | 
  •  

Pregunta

¡Esto debería ser fácil, pero no puedo encontrar la respuesta! Mis formas de ferrocarril generan un div de la que quiero deshacerme

Este es el div que los rieles generan para mí

   <div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713"/><input name="authenticity_token" type="hidden" value="Z6UAdFYt3v8d1lx4BNXq5td3OMJ223i+ruKM8Ldb+5s=" /></div>

Eché un vistazo a algunas preguntas de vista previa que sugirieron que debería usar form_authenticity_token

¿Dónde y cómo en el código puedo usar form_authenticity_token en su lugar?

¿Fue útil?

Solución

¿Qué versión de Rails estás usando?

No sé por qué quieres hacer esto. Si se trata de un problema de CSS, puede ser más específico. Nunca he necesitado hacer esto. Sin embargo…

La forma de hacerlo en 3.0.9 sería hacer un inicializador y agregar este código:

module ActionView
  module Helpers
    module FormHelper
        def extra_tags_for_form(html_options)
          snowman_tag = tag(:input, :type => "hidden",
                            :name => "utf8", :value => "&#x2713;".html_safe)

          method = html_options.delete("method").to_s

          method_tag = case method
            when /^get$/i # must be case-insensitive, but can't use downcase as might be nil
              html_options["method"] = "get"
              ''
            when /^post$/i, "", nil
              html_options["method"] = "post"
              token_tag
            else
              html_options["method"] = "post"
              tag(:input, :type => "hidden", :name => "_method", :value => method) + token_tag
          end

          tags = snowman_tag << method_tag
          content_tag(:span, tags, :style => 'margin:0;padding:0;display:inline')
        end
  end
end
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top