使用Authlogic共享用户表

时间:2010-02-16 13:47:25

标签: ruby-on-rails authlogic activeresource

我正在寻找一种解决方案,以便重复使用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>

1 个答案:

答案 0 :(得分:1)

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

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

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

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