2017-08-03 37 views
0

你能幫我嗎?我不明白如何結合。middleman link_to與image_tag在數據文件yml

我有數據文件。 datafile.yml

list: 
    - title: "Bar" 
    desc: "A bar can be classic addition to any home." 
    image: "images/bar/1.jpg" 
    id: /bar 

這是我的觀點:

<% data.categories.list.each do |x| %> 
<div id="our-work"> 
    <ul> 
     <li><a <%= link_to 'Read more', "#{x.id.to_s}.html" %> > 
     <%= image_tag x.image %> 
       <div class="overlay"> 
        <summary> 
         <h2><%= x.title %></h2> 
         <h3><%= x.desc %></h3> 
        </summary> 
       <div class="nnnext"><span></span></div></div> 
      </a> 
     </li> 
<% end %> 

我想創建的link_to +圖片標籤。在1個字符串中,該怎麼做?我希望你明白我的意思。

圖像:+ ID:=> <%=的link_to IMAGE_TAG ...%>

鏈接index.html.erb https://gist.github.com/anonymous/d356271136b1f574965c939a6ba1defb

回答

1

問題是你沒有關注的語法尤其是打開阻止並不關閉它。

這裏是基於您共享的html的正確結構。

<% data.categories.list.each do |x| %> 
    <div id="our-work"> 
    <ul> 
     <li> 
     <%= link_to "#{x.id.to_s}.html" do %> 
      <%= image_tag x.image %> 
      <div class="overlay"> 
      <summary> 
       <h2><%= x.title %></h2> 
       <h3><%= x.desc %></h3> 
      </summary> 
      <div class="nnnext"><span></span></div> 
      </div> 
     <% end %> 
     </li> 
    </ul> 
    </div> 
<% end %> 

注意:當您使用link_to主體具有的塊不能使用文本Read more而你的情況的圖像和其他HTML

+0

沒有工作:(/家庭/ lucker/git的/廚房畫廊/源/ index.html.erb:46:語法錯誤,意外的')'ore',「#{x.id.to_s} .html」do).to_s; @_out_buf <<'^ /home/lucker/git/kitchen-gallery/source/index.html.erb:59:語法錯誤,意外的keyword_end,期待')';結束^ /home/lucker/git/kitchen-gallery/source/index.html.erb:113:語法錯誤,意想不到的keyword_ensure,期待')'確保^/home/lucker/git/kitchen-gallery/source/index。 html.erb:115:語法錯誤,意外的keyword_end,期待')'結束^ – user2369480

+0

你能否更新問題並共享整個'index.html.erb'? –

+0

問題升級 – user2369480