ERB空白删除结束表达式符号( - %>)的HAML等效项是什么?

时间:2015-08-27 12:41:11

标签: ruby-on-rails haml erb

有人知道我怎样才能在纯HAML中写下以下内容?请注意,我想显示两个完全相邻的选择框,旁边是一个按钮,中间没有任何空格:

<%= f.select :state, State.all.order(:name).map {|s| [s.name, s.id]} -%>
<%= f.select :subject, Subject.all.order(:name).map {|s| [s.name, s.id]} -%>
<%= f.button "Search", class: "input-lg" -%>

编辑这包含在部分内容中,如下所示:

= form_for @tutors_search_form, url: "/tutors/search", method: :get do |f|
  .container
    .row.text-center
      :erb
        <%= f.text_field :subject, class: "input-lg input-no-border-radius", placeholder: "What Subject do you want to learn?", required: true, id: 'home-page-search-bar-subject-input' -%>
        <%= f.text_field :state, class: "input-lg input-no-border-radius", placeholder: "Which State are you in?", required: true, id: 'home-page-search-bar-state-input' -%>
        <%= f.button "Search", class: "btn btn-primary-wouaou btn-lg btn-no-border-radius", id: 'home-page-search-bar-form-button-submit' -%>

如您所见,我必须在:erb文件中使用HAML。否则,我无法生成输入标签和中间没有空白的按钮。

3 个答案:

答案 0 :(得分:5)

我认为应该是:

<= f.select :state, State.all.order(:name).map {|s| [s.name, s.id]}
<= f.select :subject, Subject.all.order(:name).map {|s| [s.name, s.id]}
<= f.button "Search", class: "input-lg"

HAML文档:

Whitespace Removal: > and <

  

><可让您更好地控制标记附近的空白。 >   将删除标记周围的所有空格,而<将删除   标签内的所有空格。你可以把它们想象成   鳄鱼吃空白:>面朝标签并吃   外面的空白,<面向标签并吃掉   内部的空白。它们放在标签的末尾   定义,类,id和属性声明之后但/之前   或=

答案 1 :(得分:0)

答案在http://haml.info/docs/yardoc/file.REFERENCE.html#whitespace_removal__and_

以上是如何回答的,除了示例不正确。只需搜索那个年龄,您就会看到正确的实施。

答案 2 :(得分:0)

我无法弄清楚如何在评论中正确格式化...

这里很快......脏:

= select_tag "locations", "<option>Home</option><option selected='selected'>Work</option><option>Out</option>".html_safe   
%span>  
= select_tag "locations", "<option>Home</option><option selected='selected'>Work</option><option>Out</option>".html_safe  
%span>  
= select_tag "locations", "<option>Home</option><option selected='selected'>Work</option><option>Out</option>".html_safe  

显然坚持使用空的SPAN标签......(我不想添加假标签,但是...