Tag: 哈姆

Haml:控制文本周围的空白

在我的Rails模板中,我想用HAML来完成这个效果的最终的HTML: I will first <a href="http://example.com">link somewhere</a>, then render this half of the sentence if a condition is met 接近的模板: I will first = link_to 'link somewhere', 'http://example.com' – if @condition , then render this half of the sentence if a condition is met 但是,您可能会注意到这会在链接和逗号之间产生一个空格。 有没有什么实际的方法来避免这个空白? 我知道有语法来删除标签周围的空白,但是这种相同的语法可以应用于文本? 我真的不喜欢额外的标记来解决这个问题。

在HAML中包含内联JS

我不喜欢我的HAML。 想知道如何写这样的东西,包括在模板中,而我在黑客中,但在HAML? <script type='text/javascript'> $(document).ready( function() { $('body').addClass( 'test' ); } ); </script>

如果Haml中的条件为真,则追加类

如果post.published? .post / Post stuff 除此以外 .post.gray / Post stuff 我用rails helper实现了这个,看起来很难看。 = content_tag :div, :class => "post" + (" gray" unless post.published?).to_s do / Post stuff 第二个变体: = content_tag :div, :class => "post" + (post.published? ? "" : " gray") do / Post stuff 有一个更简单,哈姆特定的方式? UPD。 Haml特有的,但仍然不简单: %div{:class => "post" + (" gray" unless […]

不兼容的字符编码:ASCII-8BIT和UTF-8

我使用Ruby 1.9.2和Rails 3.0.5 我有以下错误: 不兼容的字符编码:ASCII-8BIT和UTF-8 这与我认为的数据库无关。 错误是在这条线在一个视图happinging(只是一个div haml调用): #content 完整的堆栈: ActionView::Template::Error (incompatible character encodings: ASCII-8BIT and UTF-8): 21: -flash.each do |name, msg| 22: =content_tag :div, msg, :id => "flash_#{name}" 23: %div.clear 24: #content 25: = yield 26: = render :partial => "layouts/grid_right" if render_grid_right? 27: = render :partial => "layouts/footer" app/views/layouts/application.html.haml:24:in `_app_views_layouts_application_html_haml___4380000789490545718_2180251300_2717546578298801795' actionpack (3.0.5) lib/action_view/template.rb:135:in […]