Hey all, I am looking through this example Rails app where a user session is stored in cookie so user signs up in one rails app and navigates to another while still being signed in as unique user. I come across this line of code where I don't understand where some of these methods are coming from:
@session = Session.create!(:user => @user) cookies[:session_token] = {:value => @session.token, :domain => Settings.session_token_domain} 1) I look in Session class and there is no create! class method. Yet it works and doesn't throw an exception. I do understand when that create! method is called, the constructor is initialized first and generates a random number and assigns it to the token property (self.token) of the specific instance. And then stores the instance to the @session instance variable. 2) I did a global search of app and found no property or method called "session_token_domain", although there is a Session class but session_token_domain is not declared anywhere in it. The only other location is in settings.yml, which has something like this: production: <<: *default_settings session_token_domain: xxxxx So I'm not sure why this doesn't throw an exception either. 3) Finally I see that Rails supports a hash called cookies that can pass strings or symbols. Here a key is created and a value which contains subhashes is passed into it. So we store a unique session token for user. What value does this add rather than just assigning the user id in the sessions hash which is actually done in the same method: session[:user_id] = @user.id Why store them both? Thanks for response -- Posted via http://www.ruby-forum.com/. -- 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 rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.