rails經常使用語法

1.附件列表html

      ul.m_item_list
        -@page.attachment_list('手機圖片').each do |attachment|
          li
            = link_to '/posts/1', class: 'wrap' do
              = image_tag amalgam.attachment_url(attachment)
              p.des
                = attachment.description
              p.type 乾紅葡萄酒
              .button
                = image_tag('button_details.jpg')
/////=image_tag attachment.file.url
  = properties_for @page do |p|
    # 提供文本框修改 @page 對象的 title
    = p.string 'title'
    # 提供文本框修改 @page 對象的 content['title'] 屬性
    = p.string 'content.title'
    # 上傳名爲 pic 的附件
    = p.attachment 'pic'
    # 上傳名爲 pics 的附件列表
    = p.attachment_list 'pics'

 

 2.帶有index的ruby

-@page.children.each_with_index do |attachment,index|

 3.自身與兄弟元素post

-@page.parent.self_and_siblings.each do |sub_nav|

 4.properties buttonurl

      ul
        -Page.find_by_slug('tickets-top').children.each do |ticket|
          li
            =link_to(ticket.content['url'] || '#', target: '_blank') do
              =editable_image_tag ticket, 'content.image',:display => '245x162!',:placeholder_options => {:width => 245, :height => 162}
              h3=ticket.title
              h2="¥#{ticket.content['price']}"
              .btn 當即搶購
            = properties_button ticket do |f|
              = f.string 'title'
              = f.string 'content.price'
              = f.string 'content.url'
              = f.string 'content.wap_url'

 5.content_tagspa

=editable_content_tag :div,@page,'content.content',:class=>'article' do
        |

 6.content_imgcode

=editable_image_tag @page,:display => '80x371!', :placeholder => "position.png",:placeholder_options => {:width => 80, :height => 371}
展位圖不在本地時
=editable_image_tag @page,'content.produce_place',:display => '262x202!',:placeholder_options => {:width => 262, :height => 202}

 7.home是舉例子 是文件夾htm

pages
|-- home
    |-- &1.html.slim
    |-- &2.html.slim

頁面:

|-- home
      |-- child1            (home/&1.html.slim)
      |-- child2            (home/&1.html.slim)
      |   |-- grand_child   (home/&2.html.slim)

 8變量穿插對象

 h2="¥#{ticket.content['price']}"blog

  =image_tag("tag_#{tag}.jpg")圖片

9.日期

= order.created_at.strftime('%Y.%m.%d')

10.

相關文章
相關標籤/搜索