私のアプリケーションには、レールアプリケーション用とルビーアプリケーション用の2つのフォルダがあります。 rubyフォルダには、アクティブなリソースを使用しているレールアプリケーションに存在するいくつかのモデルにアクセスするためのコードを記述したルビーファイルが作成されています。 サンプルコードを以下に示します。アクティブなリソースがサービスにアクセスすることを許可しないようにする
active_resource_example.rb私のRailsアプリケーションで
require 'rubygems'
require 'active_resource'
class Website < ActiveResource::Base
self.site = "http://localhost:3000/admin/"
self.user = "user"
self.password = "password"
end
websites = Website.find(:all)
puts websites.inspect
を私は認証のために考案使用ActiveAdminの宝石を使用していました。私は、認証が考案した別のアプリケーションでこれを試してみました
[email protected]:~/Desktop$ ruby active_resource_example.rb
/home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/connection.rb:132:in `handle_response': Failed. Response code = 401. Response message = Unauthorized . (ActiveResource::UnauthorizedAccess)
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/connection.rb:115:in `request'
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/connection.rb:80:in `block in get'
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/connection.rb:218:in `with_auth'
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/connection.rb:80:in `get'
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/base.rb:894:in `find_every'
from /home/user/.rvm/gems/ruby-1.9.2-p180/gems/activeresource-3.1.1/lib/active_resource/base.rb:806:in `find'
from active_resource_example.rb:12:in `<main>'
[email protected]:~/Desktop$
:
Started GET "/admin/websites.json" for 192.168.1.37 at 2011-11-12 14:41:06 +0530
Processing by Admin::WebsitesController#index as JSON
Completed in 43ms
そして、私はactive_resource_example.rbを実行し、私の端末で、私はエラーを次しまっ:レールのサーバー上で、私は次のような結果を得ます私はactive_resource_example.rbで使用したのと同じ設定では使用されませんでしたが、そこに結果があります。 この問題の解決策が必然的に必要です。
エラーは11行目ですが、コードスニペットには11行ありません。 'active_resource_example.rb'全体をgithub要旨として投稿することは可能でしょうか? –
@Vincent Agnello:active_resource_example.rbをgithubの要点として投稿できません。しかし、私はファイルを編集して、再び投稿しました...あなたがこれから何かを得るかどうかを見てください。 –