文章出處

 想輸出如下html

<% if user.present? %>
    <li>

      <a href="<%= user_info_url(user.id) %>"><%= user.nickname %>
        <br><%= image_tag user.head_img_url %></a>

    </li>
<% else %>
    <li>

      <a href="#">空<br><%= image_tag 'blank.jpg' %></a>
      <p></p>
      <p><button class="btn btn-normal">點亮</button></p>
    </li>
<% end %>

  可以在helper中定義一個方法,內容如下:

content_tag :li do
      if user.present?
          html = link_to user_info_url(user.id) do
            concat user.nickname
            concat tag(:br)
            concat image_tag(user.head_img_url)
           
          end
         concat html
         concat content_tag :div ,'', class: 'mask'
      else
         link_to '#' do
           concat '空'
           concat tag(:br)
           concat image_tag('blank.jpg')
         end

      end

    end

  已經驗證過!


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()