2014-02-06 95 views
0

我在我的Rails应用程序中嵌套html/haml标签时遇到了问题。我有一个应用程序的默认布局:在html中嵌套html标签

!!! 
%html 
    %head 
    = render 'shared/head' 
    %body 
    = render 'shared/alerts' 
    = render 'shared/header' 
    .content 
     = yield 
    = render 'shared/footer' 

我有这个网站:

<html> 
    <head>..</head> 
    <body> 
    <div class="menubar">..</div> 
    <div class="content">..</div> 
    <div class="footer">..</div> 
    </body> 
</html> 

正如你可以看到footer超出.content的。问题是footer嵌套到.content在一个视图文件,我不知道为什么:

<html> 
     <head>..</head> 
     <body> 
     <div class="menubar">..</div> 
     <div class="content"> 
      <div class="footer">..</div> 
     </div> 
     </body> 
    </html> 

查看其中的HTML是打破

<div id='topic' class='#{'un' unless @topic.locked?}locked'> 
\#{render :partial => 'forem/topics/head', :locals => { :topic => @topic }} 

.small-offset.up 
    - if @topic.can_be_replied_to? && can?(:reply, @topic) 
    = link_to t(".reply"), forem.new_topic_post_path(@topic), class: "button medium rounded lime" 
    - if @topic.user == forem_user || forem_admin? 
    = link_to t(".delete"), forem.forum_topic_path(@forum, @topic), method: :delete, data: { confirm: t("are_you_sure") } 
    - if forem_user 
    - if [email protected]?(forem_user.id) 
     = link_to t(".subscribe"), forem.subscribe_forum_topic_path(@forum, @topic), class: "button medium rounded blue" 
    - else 
     = link_to t(".unsubscribe"), forem.unsubscribe_forum_topic_path(@forum, @topic), class: "button medium rounded pink" 
    - if forem_admin? 
    = link_to t('forem.topic.links.edit'), forem.edit_admin_topic_path(@topic) 
    = link_to t(".hide.#{@topic.hidden}"), forem.toggle_hide_admin_topic_path(@topic), method: :put 
    = link_to t(".lock.#{@topic.locked}"), forem.toggle_lock_admin_topic_path(@topic), method: :put 
    = link_to t(".pin.#{@topic.pinned}"), forem.toggle_pin_admin_topic_path(@topic), method: :put 
    - if @topic.pending_review? 
    = t(".pending_review") 
    - if forem_admin_or_moderator?(@topic.forum) 
     = form_for @topic, url: forem.moderate_forum_topic_path(@topic.forum, @topic), method: :put do |f| 
     = render "/forem/moderation/options", f: f 
    = forem_pages_widget(@posts) 
    = render partial: "forem/posts/post", collection: @posts 
    = forem_pages_widget(@posts) 
+1

我们也没有,因为我们无法看到问题的文件。我怀疑时髦的HTML,特别是如果这是你在DOM中看到的 - 浏览器试图修复破碎的HTML。 –

+0

我不太了解哈姆,但我知道缩进会有所作为。你是否尝试过缩进你的= render'共享/页脚'语句,就像yield语句是? – PhillipKregg

+0

@DaveNewton我添加了查看文件。我认为它可能不清楚,但它正是HTML打破的视图文件 –

回答

2

在那里它打破缺少结束的div视图文件标签,打开DIV:

<div id='topic' class='#{'un' unless @topic.locked?}locked'>

但不要关闭它,尝试添加</div>年底,这应该修复它

,或者甚至更好转DIV成HAML然后indentention会自行解决:

#topic{class: @topic.locked? "locked" : "unlocked"} 
    = render :partial => 'forem/topics/head', :locals => { :topic => @topic } 

    .small-offset.up 
    - if @topic.can_be_replied_to? && can?(:reply, @topic) 
     = link_to t(".reply"), forem.new_topic_post_path(@topic), class: "button medium rounded lime" 
    - if @topic.user == forem_user || forem_admin? 
     = link_to t(".delete"), forem.forum_topic_path(@forum, @topic), method: :delete, data: { confirm: t("are_you_sure") } 
    - if forem_user 
     - if [email protected]?(forem_user.id) 
     = link_to t(".subscribe"), forem.subscribe_forum_topic_path(@forum, @topic), class: "button medium rounded blue" 
     - else 
     = link_to t(".unsubscribe"), forem.unsubscribe_forum_topic_path(@forum, @topic), class: "button medium rounded pink" 
    - if forem_admin? 
     = link_to t('forem.topic.links.edit'), forem.edit_admin_topic_path(@topic) 
     = link_to t(".hide.#{@topic.hidden}"), forem.toggle_hide_admin_topic_path(@topic), method: :put 
     = link_to t(".lock.#{@topic.locked}"), forem.toggle_lock_admin_topic_path(@topic), method: :put 
     = link_to t(".pin.#{@topic.pinned}"), forem.toggle_pin_admin_topic_path(@topic), method: :put 
    - if @topic.pending_review? 
     = t(".pending_review") 
     - if forem_admin_or_moderator?(@topic.forum) 
     = form_for @topic, url: forem.moderate_forum_topic_path(@topic.forum, @topic), method: :put do |f| 
      = render "/forem/moderation/options", f: f 
    = forem_pages_widget(@posts) 
    = render partial: "forem/posts/post", collection: @posts 
    = forem_pages_widget(@posts)