问题描述
当做这个时: def user_log
如果logged_in? == false
form_tag session_path,:id => :mformdo
content_tag(:span,content_tag(text_field_tag:email,[email protected]),:class =>memail)+
content_tag(:span,content_tag(password_field_tag :密码12345678912):class =>mpass)+
content_tag(:span,content_tag(submit_tag'Login'),:class =>mbutton)
end
else
...
end
end
end
我得到这个:
由于我不想额外使用<和>,我做错了什么?
编辑:作为额外的信息,在我看来我只是在做:
<%= user_log%>
基本问题是您在使用content_tag两次你不需要。 主要调用。这是 content_tag_string
的来源:
def content_tag_string(name,content, options,escape = true)
tag_options = tag_options(options,escape)if
<#{name}#{tag_options}>#{content}< /#{name}> .html_safe
end
调用 content_tag(text_field_tag:email, [email protected])
看起来像:
<#{text_field_tag:email ,[email protected]}>
和text_field_tag已经生成完整的HTML标签(包含&和>) 。
所有你需要做的以除掉额外的角括号是省略第二个 content_tag
:
content_tag(:span,text_field_tag(:email,[email protected]),:class =>memail )+
When doing this:
def user_log
if logged_in? == false
form_tag session_path, :id => "mform" do
content_tag(:span, content_tag(text_field_tag :email, "[email protected]"), :class => "memail")+
content_tag(:span, content_tag(password_field_tag :password, "12345678912"), :class => "mpass")+
content_tag(:span, content_tag(submit_tag 'Login'), :class => "mbutton")
end
else
...
end
end
end
I get this:
stack overflow doesn't let me post pictures
Since I don't want the extra "<" and ">", what am I doing wrong?
EDIT: As extra information, on my view I am just doing:
<%= user_log %>
The fundamental problem is that you are using content_tag twice when you don't need to. content_tag essentially calls content_tag_string. Here's content_tag_string
's source:
def content_tag_string(name, content, options, escape = true)
tag_options = tag_options(options, escape) if options
"<#{name}#{tag_options}>#{content}</#{name}>".html_safe
end
Calling content_tag(text_field_tag :email, "[email protected]")
looks like:
"<#{text_field_tag :email, "[email protected]"}>"
and text_field_tag already produces a full HTML tag (it includes the "<" and ">").
All you need to do to get rid of the extra angled brackets is to leave out the second content_tag
:
content_tag(:span, text_field_tag(:email, "[email protected]"), :class => "memail")+
这篇关于Rails content_tag插入额外的“<”和“>”。人物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!