老徐

Never underestimate your power to change yourself!

About Sso in Rails

| Comments

前言

目前业务越来越多,很多业务可能需要拆分成不同的应用,不同的应用之间如何互享用户信息,这时就需要用到单点登录(Single Sign On),简称为 SSO。

这里主要针对doorkeeper作讲解

About Rails Cache

| Comments

在项目中经常会存储一些短时候内比较重要的数据,或者一些临时数据,这种数据以前一般我都把它 存到redis中,后来想想如果不是很重要的临时数据就没必要往redis里放了,直接用cache可能更方便

ActiveSupport::Cache::Store

它是一个抽象类,有很多cache store的实现 rails中的这个类提供了和缓存交互的很多基本的方法,包括(read,write,delete,exist?,fetch),下面说下具体实现

ActiveSupport::Cache::FileStore

先说一下FileStore,这种存储方式Rails默认的存储方式,他是将数据存储到系统文件,默认将文件存储到项目的/tmp/cache下面,你可以修改它的存储路径

1
config.cache_store = :file_store, "/path/to/cache/directory"

上面说FileStore是Rails默认的存储方式,看下面这句代码就知道了

1
Rails.cache.class  => ActiveSupport::Cache::FileStore

About Me

| Comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Person
  attr_accessor :name, :birthday, :gender

  def initialize(name,birthday,gender)
    @name = name
    @birthday = birthday
    @gender = gender
  end

  def company= name
    self.company = name
  end

  def position= position
    self.position = position
  end

  def hobby *arg
    "I like #{arg.split(',')}"
  end
end

me = Person.new("徐耀","1991-02-03",1)
me.nickname = %W(老徐 徐逗逗)
me.company= "上海微客来软件技术有限公司"
#TODO update at 2015-7-15
me.company= "苏州医云健康有限公司"
me.position = "Ruby Engineer"
me.hobby "coding","reading","music","traveling","grils"
me.weibo = "http://weibo.com/1676361452"

How to Understand Rails Virtual Attributes

| Comments

在网上看到关于rails virtual attributes 的例子,得觉挺好玩的,自己动手试一下,好叼

有时候在一张表里面有两个字段,但是实际表单里其实只有一个文本框输入,比如老外的名字分first_name last_name, 在表里面是分开保存的,但其实是在一个文本框中输入的,这里使用virtal attriubtes最恰当不过了,看表结构

Rails 中alias Alias_method Alias_method_chain的使用

| Comments

首先看一下alias的用法,上一个实例是明了
1
2
3
4
5
6
7
8
9
10
11
class Dog
  def say
          puts  "say hello"
  end
 alias :wang :say
end

dog = Dog.new
dog.wang

=> say hello

在类中可以将一个实例方法重新命名,注意的是新方法在前面,用空格格开

alias_method的用法,

和alias一样,只是他是module的一个私有方法,而且它的方法名可以是字符中,而alias不行,看代码

Hello Everybody

| Comments

hello everybody, this is my first post, I'am very happy, bescuse it is successful.

如果想了解微信相关开发的东西请到我的新浪博客