rails:3519
From: roppongitoppogi@y...
Date: Tue, 7 Dec 2010 14:00:03 +0900 (JST)
Subject: [rails:3519] Re: Rails3 の ActiveResource で「 undefined method `collect!'for #<Hash: 」エラーが消せない
さく様。早速の返信、ありがとうございます
外部リソースは、Railsで提供されたものではありません。詳
しい仕様は、お見せすることができない状況です。。
先の説明で、.findと書きましたが、正確には独自のメソッド
;
------------
def self.find_by_keyword keyword
find :all, :params => {:q => keyword, :inline => ''}
end
------------
となります。
何か、分かることはありますでしょうか?
--- OZAWA Sakuro <sakuro@2...> wrote:
> さくです。
>
> 対象となる外部のリソースはRailsでサーブしているものな
のでしょうか。
>
> 2010/12/7 <roppongitoppogi@y...>:
>
> > Rails3のActiveResourceで、外部のWeb API
> を呼び出す処理が
> > したいのですが、1点問題が発生しました。
> >
> >
> .findメソッドでリクエストを投げて、戻ってくる値が複数
あ
> >
> る場合はArrayなので問題ないのですが、1件しかない場合
> Hash
> > になるため、件名のようなエラーが発生します。
>
> サーバ側 Rails 3.0.3
> クライアント側 ActiveResource 3.0.3
> Ruby 1.9.0p0
> で試した限りでは、1つしかなくても配列で返って来てます
。
>
> クライアント側
> $ mkdir client
> $ cd client
> $ cat <<EOF>Gemfile
> heredoc> source :rubygems
> heredoc> gem 'activeresource'
> heredoc> EOF
> $ bundle install --quiet --path=vendor/bundle
> $ bundle console
> irb> require 'active_resource'
> irb> class Book < ActiveResource::Base; self.site =
> 'http://localhost:3000'; end
> irb> Book.find(:all)
> => [#<Book:0x00000000d10fd8
> @attributes={"created_at"=>2010-12-07
> 04:31:31 UTC, "id"=>1,
> "title"=>"Learning Ruby",
> "updated_at"=>2010-12-07 04:31:31 UTC},
> @prefix_options={}>]
> irb> Book.find(:all, :conditions => 'title =
> "Learning Ruby"')
> => [#<Book:0x00000001d0d440
> @attributes={"created_at"=>2010-12-07
> 04:31:31 UTC, "id"=>1,
> "title"=>"Learning Ruby",
> "updated_at"=>2010-12-07 04:31:31 UTC},
> @prefix_options={}>]
>
> サーバ側
> $ mkdir server
> $ cd server
> $ cat <<EOF>Gemfile
> heredoc> source :rubygems
> heredoc> gem 'rails'
> heredoc> gem 'sqlite3-ruby'
> heredoc> EOF
> $ bundle install --quiet --path=vendor/bundle
> $ bundle exec rails new . --quiet --skip-gemfile -T
> -J
> $ bundle exec rails generate scaffold Book
> title:string --quiet
> $ rake db:migrate
> $ bundle exec rails runner 'Book.create(title:
> "Learning Ruby")'
> $ bundle exec rails runner 'p Book.all'
> [#<Book id: 1, title: "Learning Ruby", created_at:
> "2010-12-07
> 04:31:31", updated_at: "2010-12-07 04:31:31">]
> $ bundle exec rails server
>
> --
> OZAWA Sakuro
>
> "I think we can agree, the past is over." - George
> W. Bush
>
> --
> ML: rails@r...
> 使い方: http://QuickML.com/
>
--------------------------------------
Learn more about HIV/AIDS - Red Ribbon Campaign 2010
http://pr.mail.yahoo.co.jp/redribbon/
--
ML: rails@r...
使い方: http://QuickML.com/
3517 2010-12-07 04:35 [roppongitoppogi@y...] Rails3 の ActiveResource で「 undefined method `collect!' for #<Hash:」エラーが消せない 3518 2010-12-07 05:44 ┗[sakuro@2... ] -> 3519 2010-12-07 06:00 ┗[roppongitoppogi@y...] 3521 2010-12-07 06:50 ┗[sakuro@2... ]