如何缩短下面的 if else 语句。
现在,这两条语句的唯一区别是第一行。手风琴体和手风琴体。折叠。
- if @office.to_i == office.id
.accordion-body{id: "collapse-#{index}"}
.accordion-inner
- office.positions.each_with_index do |position, index|
#measures-accordion.accordion
.accordion-group
.accordion-heading
.row-fluid
.span2{class: "offices-#{position.status}"}= position.status
.span1= position.results.first.value
.span2= position.results.first.value_date_time.blank? ? '' : Date.parse(position.results.first.value_date_time)
.span5= position.name
- else
.accordion-body.collapse{id: "collapse-#{index}"}
.accordion-inner
- office.positions.each_with_index do |position, index|
#measures-accordion.accordion
.accordion-group
.accordion-heading
.row-fluid
.span2{class: "offices-#{position.status}"}= position.status
.span1= position.results.first.value
.span2= position.results.first.value_date_time.blank? ? '' : Date.parse(position.results.first.value_date_time)
.span5= position.name
上面的代码有效。但是如果我把它缩短到下面,我的逻辑就行不通了
- if @office.to_i == office.id
.accordion-body{id: "collapse-#{index}"}
- else
.accordion-body.collapse{id: "collapse-#{index}"}
.accordion-inner
- office.positions.each_with_index do |position, index|
#measures-accordion.accordion
.accordion-group
.accordion-heading
.row-fluid
.span2{class: "offices-#{position.status}"}= position.status
.span1= position.results.first.value
.span2= position.results.first.value_date_time.blank? ? '' : Date.parse(position.results.first.value_date_time)
.span5= position.name