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

网上购买了安道的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. python 的math模块

    数学模块用法:import math# 或 from math import * 变量 描述 math.e 自然对数的底e math.pi 圆周率pi 函数名 描述 math.ceil(x) 对x向上 ...

  2. VisualStudio: 窗口背景颜色设置成黑色

    Tools>Options>Environment>General >Color theme

  3. FastJson(阿里巴巴)基础

    一.所需jar包: fastjson-x.x.xx.jar(本例使用fastjson-1.1.36.jar). 二.解析转化: 1.json字符串  < ------ >  js trin ...

  4. python3.4学习笔记(九) Python GUI桌面应用开发工具选择

    python3.4学习笔记(九) Python GUI桌面应用开发工具选择 Python GUI开发工具选择 - WEB开发者http://www.admin10000.com/document/96 ...

  5. C/C++之面向对象

    面向对象的三个基本特征(讲解) 面向对象的三个基本特征是:封装.继承.多态. 封装 封装最好理解了.封装是面向对象的特征之一,是对象和类概念的主要特性. 封装,也就是把客观事物封装成抽象的类,并且类可 ...

  6. ACM题目————Face The Right Way

    Description Farmer John has arranged his N (1 ≤ N ≤ 5,000) cows in a row and many of them are facing ...

  7. bzoj4591 / P4345 [SHOI2015]超能粒子炮·改

    P4345 [SHOI2015]超能粒子炮·改 题意:求$\sum_{i=1}^{k}C(n,i)\%(P=2333)$ 肯定要先拆开,不然怎么做呢(大雾) 把$C(n,i)$用$lucas$分解一下 ...

  8. 添加用户到 sudo

    sudo 简介: 在 Linux 中系统管理员可以通过 sudo 实用程序让用户或组能够作为另一个用户运行命令.换句话说,可以分派命令特权,而不需要另一个用户的密码.root 用户通过在 /etc/s ...

  9. 20145334赵文豪 WEB基础实践

    实验问题回答 1.什么是表单 表单在网页中主要负责数据采集功能 一个表单有三个基本组成部分: 表单标签 表单域:包含了文本框.密码框.隐藏域.多行文本框.复选框.单选框.下拉选择框和文件上传框等 表单 ...

  10. 把一个activity作为弹窗

    1.可以在这个activity的xml中设置其高度为某个固定高度 2.在java中:getWindow().setGravity(Gravity.BOTTOM);//设置在底部出现  getWindo ...