2014-02-25 126 views
0

我試圖創建一個網格幫手,我使用此代碼:Ruby on Rails的幫手創建網格

module ApplicationHelper 
    def grid_helper(names) 
    names.each_slice(2) do |name1, name2| 

     haml_tag 'div', class: 'column' do 
     haml_tag 'div', class: 'thumb' do 
      haml_concat link_to name1[:url] do 
      image_tag name1[:thumb], alt: name1[:description], size: '36x36' 
      end 
     end 

     haml_tag 'div', class: 'thumb' do 
      haml_concat link_to name2[:url] do 
      image_tag name2[:thumb], alt: name2[:description], size: '36x36' 
      end 
     end 
     end 
    end 
    end 
end 

在app /傭工/ application_helper.rb 呼籲HAML:

#mydiv 
    - games = [{thumb: 'foo', description: 'foobar', url: 'foo'}, {thumb: 'bar', description: 'foobarbaz', url: 'bar'}] 
    - grid_helper(games) 

所以這個放於HTML:

<div class="column"> 
    <div class="thumb"> 
    <a href="/">foo</a> 
    </div> 

    <div class="thumb"> 
    <a href="/">bar</a> 
    </div> 
</div> 

link_to不正常工作和image_tag真正做到我的幫手沒有作品,有人能幫忙嗎?

觀測值:我使用Rails4,Ruby2和SASS/HAML

+0

刪除'p'之前'link_to' – Baldrick

+0

@Baldrick刪除,但這改變不了什麼:/ –

回答

1

的問題是上下面的行:

haml_concat link_to name1[:url] do ... 

該塊用於通過haml_concat代替link_to。你可以重寫它這樣

haml_concat(link_to name1[:url] { image_tag name1[:thumb], alt: name1[:description], size: '36x36' })