Ruby China
  • Topics
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • Sign Up
  • Sign In
ping
@xiaoping_rubyist
Member
NO. 24838 / 2016-01-30

[email protected]
dell
上海
11 Topics / 74 Replies
3 Followers
5 Following
8 Favorites
GitHub Public Repos
  • playground 1

    exercise and practice

  • blog 1

    Personal Blog

  • grafana-operator 1

    Grafana Operator creates and manages Grafana deployments on Kubernetes.

  • useful-xmind-image 1

    useful-xmind-image

  • kubernetes 0

    Production-Grade Container Scheduling and Management

  • external-snapshotter 0

    Sidecar container that watches Kubernetes Snapshot CRD objects and triggers CreateSnapshot/Delete...

  • csi-driver-host-path 0

    A sample (non-production) CSI Driver that creates a local directory as a volume on a single node

  • mysql 0

    Run MySQL in Kubernetes

  • cosfs 0

  • guard 0

    🔑 Kubernetes Authentication WebHook Server

More on GitHub
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 《Ruby 源码剖析》现已上市! at December 01, 2016

    已下单,支持!

  • Elixir 会成为明日之星么?似乎是 at November 30, 2016

    #23 楼 @tony612 完了。才刚差不多学会使用 rails。。已经要被淘汰了么。。

  • 十年磨一剑,从菜鸟到 CTO —— 我的故事 at November 29, 2016

    膜拜 +1

  • T 社的卫衣到货,秀一下 at November 11, 2016

    挺好,昨天收到了 ruby-china 的卫衣,感觉还可以。100 块钱你能干啥,能买件衣服已经很不错了。

  • 如何给对象新增属性? at November 04, 2016

    #15 楼 @flemon1986 哈哈,是我在提问,还真可以了。为啥要这样呢?3.2.12 和 4.2.5 处理 json 格式为什么会有这个差别呢?谢谢啊。

  • 如何给对象新增属性? at November 03, 2016

    #13 楼 @flemon1986 这个 methods 貌似只对新添加的虚拟属性起作用,就比如 attr_accessor :testbed_name.我突然有个疑问。就是中间通过 JSON.parse 把@topology的 topology_definition_unresolved 属性重新赋值成 hash 格式。但是@topology并没有改变。他的 topology_definition_unresolved 还是原来的 String 格式。所以输出来的才是字符串而不是 json 格式的文件。

  • 如何给对象新增属性? at November 03, 2016

    #10 楼 @mystery render json: @topology

    render json: @product You don't need to call to_json on the object that you want to render. If you use the :json option, render will automatically call to_json for you.

  • 如何给对象新增属性? at November 03, 2016

    #10 楼 @mystery 转换成 hash 是对的。关键问题难道不是 render json: @topology 为什么没有把所有的数据格式化成 json 格式呢。hash 对象也可以转换成 json 格式。

    2.3.0 :052 > a = {"a" =>  1, "b" =>  2}
     => {"a"=>1, "b"=>2}
    2.3.0 :053 > a.to_json
     => "{\"a\":1,\"b\":2}"
    
  • 如何给对象新增属性? at November 03, 2016

    #6 楼 @flemon1986 谢谢,还是不行。真的跪了。一天了,愣是没搞出来。。😂

  • 如何给对象新增属性? at November 03, 2016

    @qinfanpeng @Rei 求大神们帮我解答下 二楼三楼的问题,万分感谢。。

  • 如何给对象新增属性? at November 03, 2016

    #1 楼 @huacnlee 不好意思,打扰了,想了好久,搜了好多也没找到答案。而在 Rails 3.2 里面可以输出 json 格式。

    {
    created_at: "2016-11-02T01:47:45Z",
    created_by: "weshen",
    hold_time: 30,
    location_id: 3,
    status: "TERMINATED",
    testbed_id: 232,
    testbed_name: "VTB512",
    topology_definition_resolved: {
    nodes: [
    {
    name: "UTM",
    platform: "NSA 5600",
    dut: true,
    physical: true,
    team: "UTM",
    attributes: "team=UTM,testuse=dut",
    interfaces: [
    {
    name: "X0",
    remote_node: "PC1",
    remote_interface: "eth0",
    ip: "192.168.168.168",
    network: "192.168.168.0/24",
    vlan: 272,
    physnet: "physnet1",
    external_network: "ext_net",
    switch_id: 66,
    switch_port: "gigabitethernet 0/24",
    vlan_type: "untag"
    },
    {
    name: "X1",
    network: "12.12.1.0/24",
    ip: "",
    vlan: 273,
    physnet: "physnet1",
    external_network: "ext_net",
    switch_id: 66,
    switch_port: "gigabitethernet 0/25",
    vlan_type: "untag"
    },
    {
    name: "X2",
    network: "23.0.0.0/24",
    ip: "",
    vlan: 274,
    physnet: "physnet1",
    external_network: "ext_net",
    switch_id: 66,
    switch_port: "gigabitethernet 0/26",
    vlan_type: "untag"
    },
    {
    name: "X3",
    network: "192.168.101.0/24",
    ip: "",
    vlan: 275,
    physnet: "physnet1",
    external_network: "ext_net",
    switch_id: 66,
    switch_port: "gigabitethernet 0/27",
    vlan_type: "untag"
    },
    ]
    }
    }
    
  • 如何给对象新增属性? at November 03, 2016

    #1 楼 @huacnlee 不好意思再问一下,为什么 topology_definition_resolved 没有解析成 json 格式呢?Rails 4.2.5 http://10.6.1.251:3000/topologies/47452.json

    {
    testbed_name: "VTB510",
    hold_time: 30,
    created_at: "2016-10-27T01:51:53.666Z",
    created_by: "ayzhang",
    location_id: 3,
    status: "INUSE",
    testbed_id: 230,
    topology_definition_resolved: "{"nodes"=>[{"name"=>"RemoteGEN5", "platform"=>"NSA 3500", "physical"=>true, "team"=>"UTM", "attributes"=>"team=UTM,testuse=remote", "interfaces"=>[{"name"=>"X0", "remote_node"=>"PC2", "remote_interface"=>"eth0", "network"=>"172.16.1.0/24", "ip"=>"172.1.1.1"}],}"
    }
    
  • 如何给对象新增属性? at November 03, 2016

    #1 楼 @huacnlee 谢谢,还有一个问题。 Model

    class Topology < ActiveRecord::Base
      attr_accessor :testbed_name
    end
    
    class TopologiesController < ApplicationController
      def show
         @topo = Topology.find(2)
         @topo.testbed_name = "VTB100"
    
    
        # Rails.logger.info "#{@topo.inspect}"  
    
           if params[:format] == "json" then
              @topology.topology_definition_unresolved = JSON.parse(@topology.topology_definition_unresolved)
           end
    
       respond_to do |format|
           format.html
           format.json { render json: @topology }
       end
       end
    end
    
    我想输出json格式的数据。发现并没有testbed_name这个属性。而且@topology.topology_definition_unresolved里面的数据并没有格式化成json数据。但是在3.2版本的rails里面就没问题。看了下rails upgradeguide也并没有讲到这点。
    
  • 关于 Ruby 的线上视频培训 at October 11, 2016

    听了一下,讲的也并不是很深入嘛,还是因为我没听懂?

  • 从 0 到 1 搭建移动 App 功能自动化测试平台:(0) 背景介绍和平台规划 at May 20, 2016

    坐等续集。。

  • 2016年5月21日 SH ❤ Ruby 聚会 (薄荷主办) at May 20, 2016

    20 楼不是说报名了就行么。管他呢。先去了再说。

  • HHKB Professional Type-S VS HHKB Professional BT 该选择哪款? at May 19, 2016

    #3 楼 @jimrokliu 哪有二手的?我想买个。一手太贵了。

  • 云服务器怎么选择? at May 17, 2016

    bandwagonhost.最便宜套餐 2.99.。

  • 2016年5月21日 SH ❤ Ruby 聚会 (薄荷主办) at May 12, 2016

    ding!!!

  • 我如何把薪水从 50 人民币 / 天 提升到 100 美元 / 小时的 (4) -- 迟到了两年的更新 :) at April 15, 2016

    哈哈。好玩。。

  • Agile Web Development with Rails 5 引进事宜 at April 13, 2016

    #6 楼 @andor_chen 期待中文版。看全英文总有点累,而且不一定能完全理解正确。

  • 各位同学是如何解决另一半问题的? at April 06, 2016

    春天。玩户外,春天踏青。妹子不要太多。。。。

  • gems.ruby-china.org 连不上 at March 29, 2016

    #1 楼 @lgn21st 网络没问题。ping 的通。

  • 各位觉得现在该入手 Macbook Pro 吗? at March 25, 2016

    如果不缺这个钱,果断买。何必等。

  • 微信公众号开发的疑惑 at March 21, 2016

    #1 楼 @ruby_sky 多谢,已加

  • 记 Dji 的一次面试。 at March 18, 2016

    好奇的是,没有基础知识,怎么做项目?依葫芦画瓢么?

  • 计算机开放电子书汇总 at March 15, 2016

    👍

  • Rails 升级遇到的问题。从 3.2.2 到 4.2.5 at March 15, 2016

    #3 楼 @msg7086 谢谢。rails guides 里找到了。看书还是太不认真。Rails 4.0 has deprecated the old-style hash based finder API. This means that methods which previously accepted "finder options" no longer do. For example, Book.find(:all, conditions: { name: '1984' }) has been deprecated in favor of Book.where(name: '1984')

  • Rails 升级遇到的问题。从 3.2.2 到 4.2.5 at March 14, 2016

    #1 楼 @qinfanpeng 感谢提供思路。

  • Prev
  • 1
  • 2
  • 3
  • Next
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English