带有 haml 和 simple_form 的辅助视图
我尝试将 simple_form 帮助器插入到 视图帮助器 中(抱歉双关语)并将其与 Haml::Helpers 一起使用,例如:
def front_box_search_html(form_object)
my_custom_wrapper() do
non_haml do
simple_form_for( form_object ||= Form::Search.new, :url => front_search_path ) do |f|
haml_concat f.input :phrase
haml_concat f.button :submit
end
end
end
end
但此代码未正确呈现:所有 html 代码均出现(各种 html 标签包装器、输入和标签),但 没有 标签,正如您所看到的,这是结果(使用 RSpec 进行测试,但在浏览器中是同一件事):
Failure/Error: helper.capture_haml{ helper.front_box_search_html }.should have_xpath("/html/body/div[@*]/form")
expected following text to match xpath /html/body/div[@*]/form:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
<div class= "boxSearch box">
<p class = "sum">search title</p>
<div class = "row string optional">
<label class = "string optional" for="form_search_phrase"> word</label>
<input class="string optional" id="form_search_phrase" name="form_search[phrase]" type="text">
</div>
<div class = "row buttons last">
<input class = "button" id="form_search_submit" name="commit" type="submit" value="search">
</div>
</div>
</body>
</html>
说实话我还没有完全理解如何使用Haml::Helpers的各种方法,关于文档很差。
我的环境:rails 3.0.7,haml 3.1.4,simple_form 1.5.2
I tried to insert a simple_form helper into a view helper (sorry for the pun) and using it with the Haml::Helpers, example:
def front_box_search_html(form_object)
my_custom_wrapper() do
non_haml do
simple_form_for( form_object ||= Form::Search.new, :url => front_search_path ) do |f|
haml_concat f.input :phrase
haml_concat f.button :submit
end
end
end
end
but this code is not rendered correctly: all html code appears (the various html tags wrapper, the inputs and the labels) but without the tag, As you can see this is the result (testing with RSpec, but in the browser is the same thing):
Failure/Error: helper.capture_haml{ helper.front_box_search_html }.should have_xpath("/html/body/div[@*]/form")
expected following text to match xpath /html/body/div[@*]/form:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<body>
<div class= "boxSearch box">
<p class = "sum">search title</p>
<div class = "row string optional">
<label class = "string optional" for="form_search_phrase"> word</label>
<input class="string optional" id="form_search_phrase" name="form_search[phrase]" type="text">
</div>
<div class = "row buttons last">
<input class = "button" id="form_search_submit" name="commit" type="submit" value="search">
</div>
</div>
</body>
</html>
to be honest I have not fully understood how to use various methods of Haml::Helpers, about the documentation is poor.
my env: rails 3.0.7, haml 3.1.4, simple_form 1.5.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是一个猜测,但“simple_form_for”助手也输出 html,所以我认为应该是:
Just a guess but the 'simple_form_for' helper also outputs html so I think it should be: