部分章节还没有实做练习。

网上购买了安道的Rails指南中文版。联系了这个作者问了一个问题Rails5的翻译问题。


try(), 判断是否存在,不存在的话返回nil.例子:pasting

@person.try(:name) instead of: @person.name if @person

atom订阅:

atom_feed()

atom_feed do |feed|
  feed.title "Who bought #{@product.title}"
  feed.updated(@latest_order.try(:updated_at))
  @product.orders.each do |order|
    feed.entry(order) do |entry|
      entry.title "Order #{order.id}"
      entry.summary type: 'xhtml' do |xhtml|
        xhtml.p "shipped to #{order.address}"
        xhtml.table do
          xhtml.tr do
            xhtml.th "Product"
            xhtml.th "Quantity"
            xhtml.th "Total Price"
          end
          order.line_items.each do |item|
            xhtml.tr do
              xhtml.td item.product.title
              xhtml.td item.quantity
              xhtml.td number_to_currency item.total_price
            end
          end
          xhtml.tr do
            xhtml.th 'total', colspan: 2
            xhtml.th number_to_currency(order.line_items.map(&:total_price).sum)
          end
        end
        entry.author do |author|
          author.name order.name
          author.email(order.email)
        end
      end
    end
  end
end

输出:curl --silent http://localhost:3000/products/1/who_bought.atom

得到xml格式的,可以在自己喜欢的阅读器上订阅这个Atom源。

<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:localhost,2005:/products/1/who_bought</id>
  <link rel="alternate" type="text/html" href="http://localhost:3000"/>
  <link rel="self" type="application/atom+xml" href="http://localhost:3000/products/1/who_bought.atom"/>
  <title>Who bought Rails, Angular, Postgres, and Bootstrap</title>
  <updated>2018-04-02T13:19:44Z</updated>
  <entry>
    <id>tag:localhost,2005:Order/2</id>
    <published>2018-04-02T13:19:44Z</published>
    <updated>2018-04-02T13:19:44Z</updated>
    <link rel="alternate" type="text/html" href="http://localhost:3000/orders/2"/>
    <title>Order 2</title>
    <summary type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>shipped to beijing</p>
        <table>
          <tr>
            <th>Product</th>
            <th>Quantity</th>
            <th>Total Price</th>
          </tr>
          <tr>
            <td>Rails, Angular, Postgres, and Bootstrap</td>
            <td>4</td>
            <td>$440.00</td>
          </tr>
          <tr>
            <th colspan="2">total</th>
            <th>$440.00</th>
          </tr>
        </table>
        <author>
          <name>wangming</name>
          <email>wangming@google.com</email>
        </author>
      </div>
    </summary>
  </entry>
</feed>

4-3 atom订阅源的更多相关文章

  1. 为网站加入Drupal星球制作RSS订阅源

    目前中文 Drupal 星球的版块还未成立,但大家的积极性挺高,不少站长都已经调整好自己的网站,生成了可供Drupal Planet 使用的RSS订阅源. 如果你也想让网站做好准备,可以不必再花上不少 ...

  2. WordPress基础:订阅源rss的使用

    设置->阅读,可设置rss显示效果 RSS源为:http://wordpress目录/feed 把这个地址放入你的rss阅读器进行订阅即可,最简单的就是使用QQ邮箱里面的阅读空间进行订阅.

  3. 技术博客rss订阅源收集

        http://blog.sina.com.cn/rss/2506410862.xml http://fullrss.net/a/http/www.cocoachina.com/cms/rss. ...

  4. Django实战(19):自定义many-to-many关系,实现Atom订阅

    记得有人跟我说过,rails的has_many :through是一个”亮点“,在Django看来,该功能简直不值一提.rails中的many-to-many关联中,还需要你手工创建关联表(写 mig ...

  5. Redis(十):pub/sub 发布订阅源码解析

    谈到发布订阅模式,相信不会陌生,典型的观察者模式的实现.然而从表面来看,本地实现一个wait/notify通知.register/update调用, 实现一个远程mq服务, 还有本文说的 pub/su ...

  6. xml 制作 RSS 订阅源

    首先制作一个 RSS 模板,模板的文件名是 feed.xml,代码如下: <?xml version="1.0" encoding="utf-8"?> ...

  7. solr7.5--win10--部署使用

    2018年8月份学习使用solr,当时下载的版本是solr7.5,写这篇博文的时候是2019年3月份,solr此时已经出到了8.0版本.一个大版本的变迁肯定有很多的改动,暂时还未研究就不赘述了. 此篇 ...

  8. 洗礼灵魂,修炼python(69)--爬虫篇—番外篇之feedparser模块

    feedparser模块 1.简介 feedparser是一个Python的Feed解析库,可以处理RSS ,CDF,Atom .使用它我们可从任何 RSS 或 Atom 订阅源得到标题.链接和文章的 ...

  9. JavaEE进阶——全文检索之Solr7.4服务器

    I. Solr Solr简介 Solr是Apache的顶级开源项目,使用java开发 ,基于Lucene的全文检索服务器. Solr比Lucene提供了更多的查询语句,而且它可扩展.可配置,同时它对L ...

随机推荐

  1. seo标题关键字描述字数限制Title,keywords,description长度最长多长 ?

    seo标题关键字描述字数限制 seo优化各个搜索引擎收录Title,keywords,description长度最长多长 ?SEO网站优化中Title标签的作用为重中之重,好的Title也就成功了一半 ...

  2. python3.4学习笔记(三) idle 清屏扩展插件

    python3.4学习笔记(三) idle 清屏扩展插件python idle 清屏问题的解决,使用python idle都会遇到一个常见而又懊恼的问题——要怎么清屏?在stackoverflow看到 ...

  3. CSS3实现8种Loading效果【二】

    CSS3实现8种Loading效果[二]   今晚吃完饭回宿舍又捣鼓了另外几种Loading效果,老规矩,直接“上菜“…… 注:gif图片动画有些卡顿,非实际效果! 第一种效果: 代码如下: < ...

  4. Python之路----列表推导式和生成器的表达式

    列表推导式 egg_list=['鸡蛋%s'%i for i in range(10)] print(egg_list) 列表推导式 推导过程 egg_list = [] for i in range ...

  5. python之路----黏包的解决方案

    黏包的解决方案 远程执行命令 # server 下发命令 给client import socket sk = socket.socket() sk.bind(('127.0.0.1',8080)) ...

  6. 【翻唱】Keep On Fighting

    http://video.yingtu.co/0/77868591-502c-4af1-853b-d313e83c94a9.mp4 Keep On Fighting

  7. SQL去重之distinct和group by的应用

    遇到一个需求,要去重查出某张表的字段一和字段二,但是查出来的结果要按照表中记录的创建时间排序. 于是,第一时间就想到了使用distinct这个去重专用语法了: select distinct col1 ...

  8. linux内核分析 第18章读书笔记

    十八章 调试 一.内核调试概述 1.需要面对的 一个确定的bug 一个藏匿bug的内核版本 相关的内核代码的知识和运气 2.艰难的调试工作 重现bug很困难:大部分bug通常都不是行为可靠而且定义明确 ...

  9. USACO 1.3 Ski Course Design - 暴力

    Ski Course Design Farmer John has N hills on his farm (1 <= N <= 1,000), each with an integer ...

  10. noip2015 day1

    不解释,很简单,直接按照题目的方法构造就行了 Code #include<iostream> #include<cstdio> #include<cctype> # ...