1

我正在寻找一种解决方案,以便重用另一个使用 Authlogic 的 Web 应用程序的用户表。

我正在尝试使用 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

这个练习的真正目的是构建一个只有 Authlogic 的用户表的 web 服务。应该从许多应用程序中使用此 Web 服务。

任何人有任何提示?

编辑

是的,对不起,这是我认为的错误:

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

1 回答 1

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

您不能对 ActiveResource 资源使用 new 方法。或者更好的是,您可以使用 User.new 实例化一个新用户,但创建一个没有远程属性的本地对象。尝试:

User.create :email => "mail@email.com", :password => "1234"

这将创建一个具有这些属性的远程用户。

于 2010-02-17T15:11:47.350 回答