On 2 April 2010 13:18, Marian Steinbach <[email protected]> wrote: > Hi! > I am using authlogic and I have a User model (with act_as_authentic) > without the "login" field, since I use "email" as the user name. As it > says in the authlogic documentatation, that should be the way it works > when there is no login field. > > When I create new users manually via the User -> new form, everythings > works fine. > > But: > > Now I'd like to add user accounts as a side effect when anonymous > users fill in a form (actually it's the "new" form for an entity > called SearchSubscription). > > Now, in my SearchSubscription class, I have this "before_create > :assign_user" callback: > > def assign_user > if self.user_id.nil? > # find user with the given email address. If not present, create new > user. > user = User.find(:first, :conditions => {:email => self.email}) > if !user.nil? > self.user_id = user.id > else > # User not found, so create one > randompassword = > Base64.encode64(Digest::SHA1.digest("#{rand(1<<64)}/#{Time.now.to_f}/#{Process.pid}/#{login}"))[0..7]
What is that login doing in the line above I wonder? I am not quite sure what the [0..7] is for either. > user = User.create(:email => self.email, :password => > randompassword, :location => self.location) > if user.id > self.user_id = user.id > else > flash[:warning] = "Could not create user account" > end > end > end > end > > This works well for email addresses that have a user entry. But > whenever I try to create a new SearchSubscription with an unknown > email address, I get the following error: > > NameError (undefined local variable or method `login' for > #<SearchSubscription:0x104099750>): The clue is in the error message, it is SearchSubscription that it is complaining about, not User. Colin > app/models/search_subscription.rb:26:in `assign_user' > app/controllers/search_subscriptions_controller.rb:21:in `create' > > I have the impression that somewhere, the "User" class requires the > login. But I don't want to maintain a login field, since I want to use > the email address for that. > > Any ideas? > > Thanks! > > Marian > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

