2010-04-02 4 views
0

다음 표는 formtastic 형식으로 포함 된 양식 (semantic_form_for)입니다. (루비에 의해 생성되는 모든 내가 물어 나타하지만 테이블이 심하게 망가됩니다 본질적으로, 태그가 형성되지 얻을 마십시오.왜 내 html이 잘못 형성 되었습니까?

테이블 헤더가 제대로 그려 얻을

전달받을 14 개에 구입 가능 오브젝트가 존재하며, 그들은 1 또는 2의 시간 값을 갖는 교대, 그래서 이것은 단지 정말 불허하지만 고칠 아마 간단하다 ...

<table class="availability_table"> 
    <tr> 
     <th>Date</th> 
     <th>Early</th> 
     <th>Late</th> 
    </tr> 
    <% f.fields_for :available_dates do |ad| %> 
     <% if ad.object.time == 1 #if this is an early shift, then start the new row %> 
      <tr><td><%= ad.object.date.strftime('%a, %b %d, %Y') %></td> 
       <td><%= ad.collection_select(:availability , LookupAvailability.all.collect, :id, :name) %></td> 
     <% else #otherwise end the row with just a box%> 
      <td><%= ad.collection_select(:availability , LookupAvailability.all.collect, :id, :name) %></td></tr> 
     <% end %> 
    <% end %> 
</table> 

을 내가 말한 그래서 같은 형태의 기능을 제대로하고, 객체는 모두 업데이트됩니다 올바르게 표시되고 모두 표시됩니다. HTML이 제대로 출력되지 않아 내 테이블이 모두 엉망입니다. 피!

답변

0

당신은 1.8.7을 사용하고 있습니까?

그렇다면 if 및 else 행 옆에있는 주석을 제거하십시오. erb에서 유효한 주석 구문은 < % # 주석 %>입니다. 즉, "#"은 명령 뒤에 "< %"바로 다음에 시작 부분에 있어야합니다. 루비 1.8.7에서는 렌더링 된 html을 망가 뜨리는 무작위로 충돌합니다.

+0

브릴리언트. 고맙습니다. =) – alkaloids

0

tr 태그는 else 지점에서만 닫습니다. if-else 후에 그것을 닫는 것이 합리적 일 것입니다.

2

이 시도 :

<% f.fields_for :available_dates do |ad| %> 
    <tr> 
    <% if ad.object.time == 1 #if this is an early shift, then start the new row %> 
     <td><%= ad.object.date.strftime('%a, %b %d, %Y') %></td> 
     <td><%= ad.collection_select(:availability , LookupAvailability.all.collect, :id, :name) %></td> 
    <% else #otherwise end the row with just a box%> 
     <td><%= ad.collection_select(:availability , LookupAvailability.all.collect, :id, :name) %></td> 
     <td></td> 
    <% end %> 
    </tr> 
<% end %> 

나는 <tr></tr> 위치를 변경하고 빈 테이블 셀을 추가 <td></td>을 추가했다.

관련 문제