<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dohkoos's blog</title>
	<atom:link href="http://dohkoos.name/feed" rel="self" type="application/rss+xml" />
	<link>http://dohkoos.name</link>
	<description>Do one thing, and do it well.</description>
	<lastBuildDate>Sat, 13 Feb 2010 11:54:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android下显示本地Contact Number信息（续）</title>
		<link>http://dohkoos.name/display-the-local-contact-number-on-android-continued.html</link>
		<comments>http://dohkoos.name/display-the-local-contact-number-on-android-continued.html#comments</comments>
		<pubDate>Sat, 13 Feb 2010 11:54:41 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=969</guid>
		<description><![CDATA[前文的代码只能显示联系人的第一个号码，很不方便。如果要列出联系人的所有号码，需要将People.CONTENT_URI改为Phones.CONTENT_URI。具体代码如下：

package name.dohkoos;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class ContactKit extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contact_list);

        ListView contactList = (ListView)findViewById(R.id.contactList);

    [...]]]></description>
		<wfw:commentRss>http://dohkoos.name/display-the-local-contact-number-on-android-continued.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何获取Android手机的型号</title>
		<link>http://dohkoos.name/how-to-obtain-the-android-mobile-phone-model.html</link>
		<comments>http://dohkoos.name/how-to-obtain-the-android-mobile-phone-model.html#comments</comments>
		<pubDate>Fri, 05 Feb 2010 01:31:22 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=968</guid>
		<description><![CDATA[怎么样才能获的Android手机的型号呢？例如HTC Hero或HTC Magic等名字。android.os.Build类有很多静态属性可以获得机器的信息，其中的MODEL属性就指代手机型号。

package name.dohkoos.lesson;

import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
import android.widget.TextView;

public class QueryProductModel extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv = new TextView(this);
        tv.setText(&#34;Product Model: &#34; [...]]]></description>
		<wfw:commentRss>http://dohkoos.name/how-to-obtain-the-android-mobile-phone-model.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android下显示本地Contact Number信息</title>
		<link>http://dohkoos.name/display-the-local-contact-number-on-android.html</link>
		<comments>http://dohkoos.name/display-the-local-contact-number-on-android.html#comments</comments>
		<pubDate>Sat, 23 Jan 2010 14:26:55 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=967</guid>
		<description><![CDATA[首先要在AndroidManifest.xml中配置允许读取联系人的权限：

&#60;uses-permission android:name=&#34;android.permission.READ_CONTACTS&#34; /&#62;

contact_list.xml

&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;LinearLayout xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34;
      android:orientation=&#34;vertical&#34;
      android:layout_width=&#34;fill_parent&#34;
      android:layout_height=&#34;fill_parent&#34;&#62;
    &#60;ListView android:id=&#34;@+id/contactList&#34;
        android:layout_width=&#34;fill_parent&#34;
        android:layout_height=&#34;wrap_content&#34; /&#62;
&#60;/LinearLayout&#62;

contact_entry.xml

&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;LinearLayout xmlns:android=&#34;http://schemas.android.com/apk/res/android&#34;
      android:layout_width=&#34;fill_parent&#34;
 [...]]]></description>
		<wfw:commentRss>http://dohkoos.name/display-the-local-contact-number-on-android.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Rails 2.3打造简单记账软件(12)</title>
		<link>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-12.html</link>
		<comments>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-12.html#comments</comments>
		<pubDate>Tue, 05 Jan 2010 08:31:28 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[acts_as_taggable_on_steroids]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=966</guid>
		<description><![CDATA[在这以前我们把tags作为Entry的一个字段来实现，这样做有很大的局限性，而且还有好多插件可以实现这个功能，现在我们就来把它替换用插件acts_as_taggable_on_steroids实现。
安装插件

script/plugin install git://github.com/jviney/acts_as_taggable_on_steroids.git
script/generate acts_as_taggable_migration
rake db:migrate

在Entry中添加一句代码

class Entry &#60; ActiveRecord::Base
  acts_as_taggable

  belongs_to :user
end

还要将所有视图中原来的tags字段替换成tag_list字段。
index.html.erb

&#60;td&#62;&#60;%=h entry.tag_list %&#62;&#60;/td&#62;

edit.html.erb

&#60;%= f.text_field :tag_list %&#62;

new.html.erb

&#60;%= f.text_field :tag_list %&#62;

还要将entry.rb中的验证字段tags改成tag_list。做完这些插件也就安装完成了。
既然用了插件，那么原来的tags字段就不需要了，写个迁移任务把它处理掉吧！

script/generate migration remove_tags_from_entry

迁移代码如下：

class RemoveTagsFromEntry &#60; ActiveRecord::Migration
  def self.up
    remove_column :entries, :tags
  end

  def self.down
    add_column :entries, :tags, :string
  end
end

]]></description>
		<wfw:commentRss>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-12.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Rails 2.3打造简单记账软件(11)</title>
		<link>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-11.html</link>
		<comments>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-11.html#comments</comments>
		<pubDate>Tue, 05 Jan 2010 04:43:29 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[exception_notification]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=965</guid>
		<description><![CDATA[当网站出现问题时，让它发送一份错误报告到你的邮箱是件挺不错的事，这样你就不必再担心不能及时发现问题了。
exception_notification插件的功能就是当你的Rails应用出错时，它会向指定的邮箱地址发送错误日志。
使用很简单，安装插件后配置一下邮件接受者就可以了。
安装插件

script/plugin install git://github.com/rails/exception_notification.git

在config/environment.rb中增加邮件接收者的地址

Rails::Initializer.run do &#124;config&#124;
  ...
end

ExceptionNotifier.exception_recipients = %w(youremail@domain.com)

然后告诉Exception Notifier哪些controller出错才发送日志，当然是全部啦：

class ApplicationController &#60; ActionController::Base
  include ExceptionNotifiable
  ...
end

Exception Notifier采用Rails中的ActionMailer发送邮件，所以使用的前提是确保ActionMailer可以正常发送邮件。还有就是Exception Notifier默认只在production环境下才会生效，如果想要在development下也生效，需要将development.rb文件中的

config.action_mailer.raise_delivery_errors = false

修改为

config.action_mailer.raise_delivery_errors = true

]]></description>
		<wfw:commentRss>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-11.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Rails 2.3打造简单记账软件(10)</title>
		<link>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-10.html</link>
		<comments>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-10.html#comments</comments>
		<pubDate>Mon, 04 Jan 2010 04:34:41 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[i18n]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=964</guid>
		<description><![CDATA[从2.2版本起Rails开始内置支持i18n，因此以后实现国际化/本地化就可以不再需要各种各样的插件了。
Rails默认的locale文件夹是config/locales，假设你要支持中文和英文，那么你需要在这个文件夹下放置zh.yml和en.yml两个文件。
相应的入门教程网上有不少，我也就不多讲了。这里主要说一下如何在记账应用中实现可以让用户指定语言的i18n实现，即当用户选择English，那么界面就切换成英文界面，并且以后打开的页面也是以英文出现，反之亦如此。
首先在header区添加以下代码：

&#60;%= link_to 'Chinese', :locale =&#62; 'zh' %&#62;
&#60;%= link_to 'English', :locale =&#62; 'en' %&#62;

点击其中某个链接后，浏览器就会传递对应的参数zh或en到后台。
然后在app/controllers/application_controller.rb中添加以下代码：

before_filter :set_locale

def set_locale
  I18n.locale = params[:locale]
end

不过这里有个问题就是url中必须得带着参数，不然的话用户的选择就会失效。要想使选择达到持续的效果，可以考虑把这些信息保存在session中，改进后的代码如下：

def set_locale
  I18n.locale = params[:locale] &#124;&#124; session[:locale]
  session[:locale] = I18n.locale
end

现在这样就基本上差不多了。剩下的就是处理第一次访问时的语言，这个可以从http头中的ACCEPT_LANGUAGE参数获取。最终实现的代码：

def set_locale
  accept_lang = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first
  I18n.locale = params[:locale] &#124;&#124; session[:locale] &#124;&#124; accept_lang &#124;&#124; 'zh'
  session[:locale] = I18n.locale
end

不过当用户设置locale后，在新建Entry时会报出以下的异常：

can't convert Symbol into String

Extracted source (around [...]]]></description>
		<wfw:commentRss>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-10.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>升级Rails到2.3.5</title>
		<link>http://dohkoos.name/upgrade-rails-to-235.html</link>
		<comments>http://dohkoos.name/upgrade-rails-to-235.html#comments</comments>
		<pubDate>Wed, 30 Dec 2009 06:45:57 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=963</guid>
		<description><![CDATA[许多网上的Rails开源项目使用的版本都是2.0.x，因此在2.3.5下运行的时候会出现如

uninitialized constant ApplicationController

这样的错误。解决该问题的办法是修改config/environment.rb中的RAILS_GEM_VERSION为2.3.5，再运行：

rake rails:update

即可。该任务会把app/controller下的application.rb改名为application_controller.rb。
]]></description>
		<wfw:commentRss>http://dohkoos.name/upgrade-rails-to-235.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何导入/导出Heroku中应用的数据</title>
		<link>http://dohkoos.name/how-to-import-or-export-data-from-the-app-of-heroku.html</link>
		<comments>http://dohkoos.name/how-to-import-or-export-data-from-the-app-of-heroku.html#comments</comments>
		<pubDate>Sun, 27 Dec 2009 20:43:03 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Heroku]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=962</guid>
		<description><![CDATA[导入/导出Heroku上的数据需要安装Taps包：

sudo gem install taps

导入数据到Heroku里：

heroku db:push

导出数据到本地：

heroku db:pull

其中导入/导出数据由config/database.yml配置设定。
Heroku还支持主机到主机的数据库传输，具体细节可以参考http://docs.heroku.com/taps。
]]></description>
		<wfw:commentRss>http://dohkoos.name/how-to-import-or-export-data-from-the-app-of-heroku.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>如何联机调试Android程序</title>
		<link>http://dohkoos.name/how-to-process-online-debugging-android.html</link>
		<comments>http://dohkoos.name/how-to-process-online-debugging-android.html#comments</comments>
		<pubDate>Sat, 26 Dec 2009 03:54:41 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=961</guid>
		<description><![CDATA[1. 首先你需要一台开发手机，如果不是的话可以刷ROM
2. 在Settings -&#62; Applications -&#62; Development下激活USB debugging选项
3. 下载并安装USB驱动程序
http://handheld.softpedia.com/progDownload/HTC-Hero-Drivers-Download-81097.html
4. 用USB数据线连接手机与电脑
5. 在AndroidManifest.xml中的&#60;application&#62;里添加android:debuggable="true"
6. 然后你就可以像平常一样调试你的Android代码了
]]></description>
		<wfw:commentRss>http://dohkoos.name/how-to-process-online-debugging-android.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>用Rails 2.3打造简单记账软件(9)</title>
		<link>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-9.html</link>
		<comments>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-9.html#comments</comments>
		<pubDate>Sun, 20 Dec 2009 04:45:19 +0000</pubDate>
		<dc:creator>dohkoos</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://dohkoos.name/p?=960</guid>
		<description><![CDATA[没啥多说的，继续开始干活。
修改app/views/entries/index.html.erb为：

&#60;h1&#62;Listing entries&#60;/h1&#62;

&#60;table&#62;
  &#60;thead&#62;
    &#60;tr&#62;
      &#60;th class=&#34;center&#34;&#62;Date&#60;/th&#62;
      &#60;th class=&#34;center&#34;&#62;Amount&#60;/th&#62;
      &#60;th class=&#34;center&#34;&#62;Tags&#60;/th&#62;
      &#60;th class=&#34;center&#34;&#62;Comment&#60;/th&#62;
      &#60;th class=&#34;center&#34;&#62;Action&#60;/th&#62;
    &#60;/tr&#62;
  &#60;/thead&#62;

  &#60;tbody&#62;
    &#60;% [...]]]></description>
		<wfw:commentRss>http://dohkoos.name/use-rails-23-to-create-a-simple-accounting-software-9.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
