2010-02-16 37 views
1

我正在尋找一個解決方案,以便重用使用Authlogic的另一個Web應用程序的用戶表。與Authlogic的共享用戶表

我想用ActiveResource(在新的應用程序),但我失去了一些東西。這是不工作代碼:

#Existing app 
class User < ActiveRecord::Base 
    attr_accessible :username, :email, :password 
    acts_as_authentic 
end 

#New app 
class User < ActiveResource::Base 
    self.site="http://localhost:3001" 
end 

這個練習的真正目的是要建立一個web服務只與Authlogic的用戶表。這個Web服務應該從許多應用程序中使用。

任何人有任何提示?

編輯

是的,對不起,這是我認爲的錯誤:

NoMethodError in Users#new 
Showing app/views/users/_form.html.erb where line #5 raised: 
undefined method `username' for #<User:0x103477bc0> 
+0

有什麼不合作呢?你有什麼錯誤嗎? –

+0

ActiveResource定義中缺少element_name聲明會成爲問題嗎? http://api.rubyonrails.org/classes/ActiveResource/Base.html – tadman

+0

它不應該是因爲我不需要self.element_name =「user」,因爲模型具有相同的名稱。 – Irukandji

回答

1
undefined method `username' for #<User:0x103477bc0> 

不能使用上的ActiveResource資源的新方法。或者更好的是,你可以使用User.new實例化一個新用戶,但創建一個沒有遠程屬性的本地對象。 嘗試用:

User.create :email => "[email protected]", :password => "1234" 

這創建具有這些屬性的遠程用戶。