I currently use Authlogic in a web-app to handle user authentication, but have now decided to create a limited API which would seem to require the use of a single_access_token. My question is, how can I apply the migration to existing users?
I thought using something like
add_column :users, :single_access_token, :string
User.reset_column_information
User.find(:all) do |c|
c.update_attribute :single_access_token, *****
end
I don't know if this is the best way, or what to put in 开发者_StackOverflow社区place of the ***** to generate a token for all already-registered users.
Thanks
I think
User.all.each{ |x| x.reset_single_access_token! }
is what you're looking for
Might be quicker if you have a lot of users:
User.find_each do |user|
tok = Authlogic::Random.friendly_token
str = "UPDATE users SET single_access_token = '#{tok}' WHERE id = #{user.id}"
ActiveRecord::Base.connection.update_sql(str)
end
精彩评论