いつもrailsで迷うんだけど、rootのコントローラって何がいいかしら。 37sの人はwelcome、has_manyの人はhomeを使うみたい。さっきtweetしてみたら、@shachiさんがtopとreplyしてくれた。

  1. top
  2. home
  3. welcome

上記の順でいいと思いました。
welcomeはindexだけだといいけど、aboutにも使おうとすると名前が合わない気がするし、homeだとみんなのというより自分だけ・personalな雰囲気がする/もあるし、topにはそれがなくてrootという感じもする。
今のprojectもtopしてみようかしらん!

posted by Png satoko on Mon 7 Apr 2008 at 02:19

http://livedocs.adobe.com/air/1/devappshtml/help.html?content=SQL_20.html#1085042

自分用で訳してみたのですが、よく知られたプラクティスが多かったように思います。

  • Pre-create database connection
    アプリ立ち上げ時に open()/openAsync()しておく

  • Reuse database connection
    作成したconnectionはアプリ全体で使いまわす

  • Favor asynchronous execution mode
    同期と非同期をうまく使いこなそう。データを1行追加するようなINSERTはsynchronousでやればいいが(ほとんど時間がかからないので)、複雑なSELECTの場合asynchronousのほうがいいかもしれない(でないとユーザはレスポンスが帰るまでユーザはなにもできない)。

  • Use separate SQL statements and don't change the SQLStatement's text property.
    4つのSQL処理があったら、4つのSQLStatementを作ろう。

  • Use statement parameters
    Statement文字列に入力データを入れないで、必ずパラメータを使ってすること。

  • Use constants for column and paramter names
    スペルエラーを防ぐため、カラム名を持つ文字列定数を作成する。パラメータ名を持つ同様のものも作ってもよい。

posted by Png satoko on Mon 7 Apr 2008 at 00:12

DBでDATETIME型で保存していたのですが、1.0で動かそうとしたらupdated_at(flash側ではDate)がInvalidDateと表示されてしまう。MYSQLクライアントでSELECTしたら特に問題なさそう。??と思ったのですが動いたのでメモ。

修正したところ

  • DB側はDATETIMEではなくてDATE
    下にあるように親和性が高いカラムのほうが楽だと判断しDATE型にしました。DATEといっても日付と時間も格納してくれます。
  • parameterで渡すのはDateのインスタンス
    getTime()だとNumberが帰ってしまうので、INSERTはOKなんだけど、SELECTしてblog.updated_atとすると”Invalid Date”といわれてしまう。

   1  stmt.parameter[":updated_at"] = new Date(); //OK
   2  stmt.parameter[":updated_at"] = new Date().getTime(); //NG:beta3までは動いてた

サポートされるSQLの仕様:local database

http://livedocs.adobe.com/air/1/jslr/localDatabaseSQLSupport.html

サポートされる型で特に親和性が高いもの

The affinity of a column is the recommended type for data stored in that column. When a value is stored in a column (through an INSERT or UPDATE statement), the runtime attempts to convert that value from its data type to the specified affinity
http://livedocs.adobe.com/air/1/jslr/localDatabaseSQLSupport.html#columnAffinit

下記のカラムとは親和性があり、実行時にデータ型を変換してくれるそうです。

  • TEXT (or STRING)
  • NUMERIC
  • INTEGER
  • REAL (or NUMBER)
  • BOOLEAN
  • DATE
  • XML
  • XMLLIST
  • OBJECT
  • NONE

DATEの親和性

A column with DATE affinity stores date and time values. A DATE column is designed to accept values that are ActionScript or JavaScript Date instances. If an attempt is made to store a String value in a DATE column, the runtime attempts to convert it to a Julian date. If the conversion fails an error occurs. If code attempts to store a Number, int, or uint value, no attempt is made to validate the data and it is assumed to be a valid Julian date value. A DATE value that's retrieved using a SELECT statement is automatically converted to a Date instance. DATE values are stored as Julian date values using the REAL storage class, so sorting and comparing operations work as you would expect them to.

NOTE:太字は私が強調をつけたところです。

posted by Png satoko on Wed 26 Mar 2008 at 10:08

via: http://blog.obiefernandez.com/content/2008/03/big-name-compan.html

フツーにいっぱいありますね。JP Morganみたいな硬いところが使っているのが新鮮。けど社内用がメインかしらん。

http://www.workingwithrails.com/high-profile-organisationsより

  • amazon.com
  • BBC
  • CapGemini
  • BPN
  • Cisco
  • C|Net
  • EA (Electronic Arts)
  • IBM
  • JP Morgan
  • NASA
  • Oakley
  • Oracle
  • Siemens
  • ♫ ThoughtWorks ♫
  • Yahoo!

Obieさんのクライアント、友達から聞いて多分使っているところ

  • John Deere
  • New York Times
  • NBC
  • Barclays
  • LA Times
  • Chicago Tribune
  • Orbitz
  • Google
  • Turner Media
  • Limewire

http://rails100.pbwiki.com/より

  • twitter.com [642 !!?! I thought it would be higher]
  • scribd.com [940]
  • blingee.com [1170]
  • yellowpages.com [1734]
  • penny-arcade.com [2069]
  • 43things.com [4190]
  • kongregate.com [4488]
  • pitchforkmedia.com [4740]
  • projectpath.com [5041 One of the Basecamp hostnames]
  • funnyordie.com [5089]
posted by Png satoko on Sat 22 Mar 2008 at 22:30

下記の日本語ページに説明がありますが、svnのコミットメッセージにIssueIDを入れることでcloseしたり関連付けたりすることができます。

http://redmine.jp/tech_note/subversion/

   1  $ svn commit -m '○○○機能を利用時の△△△な問題を修正。 refs 123'

しかし、実際には英語ページにあるように#123などのように#がないとRedmineに認識されません。
3/12 (追記) #がなくても(#をつけても、どちらでも)ちゃんと関連付け/closeされます。前田@Redmine.JPさんに指摘いただきました。ありがとうございまっす。

http://www.redmine.org/wiki/1/RedmineSettings

   1  This commit refs #1, #2 and fixes #3

ちなみにDefaultのキーワードは下記。+IssueIDは空白、カンマ、&で分割されます。

  • for referencing issues: refs, references, IssueID
  • for fixing issues: fixes, closes

After a keyword issue IDs can be separated with a space, a comma or &.

posted by Png satoko on Fri 7 Mar 2008 at 11:28 with 2 comments

プラグインを作るのに手間取ったのでメモ。
ARに機能を追加させるようなプラグインのテストを書く際、AR派生クラスをnewしてメソッドを呼び動作を確かめたりしたくなります(私の場合、privateメソッドを呼びたくなった)。でもテストのためだけにテーブルを作るのはばからしい。でMockを使う方法、ARのテスト用Mockの登場です。

ポイントとしては、MockBaseで一旦ARを派生させてから、MockBaseを派生させたクラスを作るのがミソです。そうすることで他のテストに影響を与えないようにすることができます(tips from takiuchi)。

あともう一つ、environment.rbをズズーっとロードすることでRails全体を読み込むことができます。それによってARを使えるようになります。

   1  #acts_as_notifiable_test.rb
   2  begin
   3    require File.dirname(__FILE__) + '/../../../../config/environment'
   4  rescue LoadError
   5    require 'rubygems'
   6    gem 'activerecord'
   7    require 'active_record'
   8  end
   9  
  10  class MockBase < ActiveRecord::Base; end
  11  MockBase.class_eval do
  12    alias_method :save, :valid?
  13    def self.columns() @columns ||= []; end
  14  
  15    def self.column(name, sql_type = nil, default = nil, null = true)
  16      columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type, null)
  17    end
  18  end
  19  
  20  class MockModel < MockBase
  21    acts_as_notifiable :callback => :after_create, :message => "hello", :recipients => "test@gmail.com"
  22  end
  23  
  24  class ActsAsNotifiableTest < Test::Unit::TestCase
  25    def test_option_message_string
  26      assert_equal "hello", MockModel.new.instance_eval{jabber_message}
  27    end

Reference

posted by Png satoko on Thu 6 Mar 2008 at 10:57

自分用メモ。

  • Object#instance_evalを使う
  • インスタンスに対してでないとだめ
    • NG: Object.instance_eval
    • OK: Object.new.instance_eval

Example

   1  class Post
   2    private 
   3    def title; "My blog"; end
   4  end

   1  p = Post.new
   2  p.instance_eval(title)
   3  # => "My blog"

Reference

http://doc.loveruby.net/refm/api/view/method/Object/i/instance_eval

posted by Png satoko on Thu 6 Mar 2008 at 10:24

Redmineを使っていて、Issueの追加/変更通知がGTalkで来たらうれしいかもと思って作りました:acts_as_notifiable。

NOTE:

Repository

http://svn.s21g.com/public/rails/plugins/acts_as_notifiable/

Redmineに組み込む

  1. XMPP4Rをインストール: http://xmpp4r.rubyforge.org/

       1  $sudo gem install xmpp4r
    

  2. プラグインをインストール

  3. 設定ファイルを作成: #{RAILS_ROOT}/config/acts_as_notifiable.yml
       1  #{RAILS_ROOT}/config/acts_as_notifiable.yml
       2  to:
       3    recipients: you@gmail.com me@gmail.com
       4  from:
       5    id: your_notify_account@gmail.com
       6    password: pass
       7    connect: talk.google.com
    
  4. モデルにacts_as_notifiableを追加
       1  class Issue
       2    acts_as_notifiable :message => Proc.new {|o| "[#{o.project.name}:#{o.class.name}##{o.id}]#{o.status.name}:#{o.subject}\n #{o.journals.last.notes unless o.journals.blank?}"}
    
  5. サーバ再起動

NOTE: 通知を受け取るIM側でyour_notify_account@gmail.comを追加するの忘れないように!

posted by Png satoko on Thu 6 Mar 2008 at 05:29

英語の記事を書いていて、「私にemail送って」が"send it to me"だったか、"send it for me"だったか悩んだりするときにぐぐると便利です。この場合はどちらも意味としては通ると思いますが、前者のほうが一般的のように思います。

"send * me"でぐぐる

前置詞がわからない場合。
http://www.google.com/search?name=f&hl=en&q=send+*+me
するとSend a copy to me.という文等がハイライトされて、toが良さそうだと判断できます。

"send to me", "send for me"でぐぐって検索結果数を比較する

どっちの用例が一般的かよくわからない場合。
検索結果が多いほうがよく使われると推測できるので、"send it to me"を使うほうがいいと判断します。自分の意図したいことが何なのか考えて選択して下さい。

本もあります

posted by Png satoko on Tue 4 Mar 2008 at 14:02

OpenIdAuthenticationはruby-openid1.1.4にしか対応していません。ですが、gem1.0.1では1.1.4が正しく動作しないため、プラグインにパッチをあてて使うことにしました。

  1. ruby-openidをインストール(2.0.4)

       1  gem install ruby-openid
    

  2. pluginのインストール

       1  $ ./script/plugin install http://svn.rubyonrails.org/rails/plugins/open_id_authentication/
    

  3. パッチをあてる

    • パッチを入手ticket10604.diffとして保存
      http://dev.rubyonrails.org/ticket/10604

    • プラグインのところに移動させておく

         1   #{RAILS_ROOT}/vendor/plugins/open_id_authentication/ticket10604.diff
      

    • プラグインのルートに移動して、patchを当てる

         1  $ patch -p1 < ticket10604.diff
         2  patching file init.rb
         3  Hunk #1 FAILED at 1.
         4  1 out of 1 hunk FAILED -- saving rejects to file init.rb.rej
         5  patching file lib/generators/open_id_authentication_tables/open_id_authentication_tables_generator.rb
         6  patching file lib/generators/open_id_authentication_tables/templates/migration.rb
         7  patching file lib/open_id_authentication.rb
         8  Hunk #5 succeeded at 69 with fuzz 1 (offset -2 lines).
         9  Hunk #6 succeeded at 88 (offset -2 lines).
        10  Hunk #7 succeeded at 152 (offset -2 lines).
        11  patching file lib/open_id_authentication/association.rb
        12  patching file lib/open_id_authentication/db_store.rb
        13  patching file lib/open_id_authentication/nonce.rb
        14  patching file lib/open_id_authentication/setting.rb
        15  patching file tasks/open_id_authentication_tasks.rake
        16  patching file test/normalize_test.rb
        17  patching file test/open_id_authentication_test.rb
        18  patching file test/status_test.rb
      

  4. READMEにあるExampleの作業

    • テーブル作成

         1   rake open_id_authentication:db:create 
      

    • routesに下記を加える

         1    map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
         2    map.resource :session
      

    • SessionsController、vews/sessions/new.html.erbの作成
      ここでmatakeさんと同じようにはまったのですが、SessionConroller#open_id_authenticationをREADMEにあるresult.successful?のほうを使うとプラグインに手を入れずに使うことができます。(agilewebdevelopment.comのExampleを使うとNG)

         1      def open_id_authentication
         2        authenticate_with_open_id do |result, identity_url|
         3          if result.successful? && @current_user = @account.users.find_by_identity_url(identity_url)
         4            successful_login
         5          else
         6            failed_login(result.message || "Sorry, no user by that identity URL exists (#{identity_url})")
         7          end
         8        end
         9      end
      

  5. ruby-openidのバージョン指定をはずす

       1  #open_id_authentication/init.rb
       2  begin
       3  #  gem 'ruby-openid', '=1.1.4'
       4    gem 'ruby-openid'
    

参考

posted by Png satoko on Wed 27 Feb 2008 at 16:40
Contents
Controller名の好み:welcome, home, top
AIRでのローカルDBのベストプラクティス(訳)
AIR 1.0対応で手間取ったこと:Dateと実行時の型変換
Railsを使っているビッグネーム by RailsWayの人
RedmineのIssueをSVNから更新する:refs #123, closes #124
ActiveRecordのテスト用Mockの作り方
Objectのprivateメソッドの呼び出し方法
acts_as_notifiable: Jabberを使って通知を送るRails plugin
英語の記事を書くときのちょっとした文法チェックにぐぐる
OpenIdAuthenticationを使う: Rails2.x + gem 1.0.1 + ruby-openid2.0.4
Comments
KingofSmack: Here also good reads for this mobile applicatio... '14-5
satoko: stackoverflowでも同じエラーを挙げている人がいたので、1.3でアップロードしたよっ... '10-12
ujihisa: :%s/blog/glob/g '10-7
satoko: しゅが〜様 返事が遅くなって申し訳ありません。また、投稿百景ご購入ありがとうございます。 ... '09-10
しゅが~: こんにちは。投稿百景を発売日翌日から利用しています。本当にいいAppを作っていただきました。罫... '09-10
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ