码迷,mamicode.com
首页 > 其他好文 > 详细

rails常用语法

时间:2016-07-20 17:54:11      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:

1.附件列表

      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的

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

 3.自身与兄弟元素

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

 4.properties button

      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_tag

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

 6.content_img

=editable_image_tag @page,:display => ‘80x371!‘, :placeholder => "position.png",:placeholder_options => {:width => 80, :height => 371}

 7.home是举例子 是文件夹

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‘]}"

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

rails常用语法

标签:

原文地址:http://www.cnblogs.com/forgere/p/5689070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!