Authenticity_Tokenフォームから生成された任意のdivを削除します
-
27-10-2019 - |
質問
これは簡単なものですが、答えが見つかりません!私のレールフォームは、私が取り除きたいDivを生成します
これは、Railsが私のために生成するDivです
<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"/><input name="authenticity_token" type="hidden" value="Z6UAdFYt3v8d1lx4BNXq5td3OMJ223i+ruKM8Ldb+5s=" /></div>
プレビューの質問を見て、使用する必要があることを提案していました form_authenticity_token
代わりに、コードのどこでどのようにform_authenticity_tokenを使用できますか?
解決
どのバージョンのレールを使用していますか?
なぜあなたがこれをしたいのかわかりません。 CSSの問題であれば、より具体的にすることができます。私はこれをする必要がありませんでした。でも…
3.0.9でそれを行う方法は、初期イザーを作成し、このコードを追加することです。
module ActionView
module Helpers
module FormHelper
def extra_tags_for_form(html_options)
snowman_tag = tag(:input, :type => "hidden",
:name => "utf8", :value => "✓".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
所属していません StackOverflow