Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Allen Chun's Profile

GitHub User: ChunAllen

Comments by Allen Chun

Avatar

Hi I just want to ask on how to configure live email account by Microsoft on

My Gmail config that is working
config/environments/development.rb
config.action_mailer.default_url_options = { host: "example.com" }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "localhost",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

how about the live email account configuration that is similar with gmail smtp configuration?
example
username: myemail@live.com
password: SamplePassword

Thanks!

Avatar

Hi I just want to ask on how to configure live email account by Microsoft on

My Gmail config that is working

config/environments/development.rb
config.action_mailer.default_url_options = { host: "example.com" }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "localhost",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: ENV["GMAIL_USERNAME"],
  password: ENV["GMAIL_PASSWORD"]
}

how about the live email account configuration that is similar with gmail smtp configuration?
example
username: myemail@live.com
password: SamplePassword

Thanks!

Avatar

Hi I have a problem, only the first row of my table is the right chosen dropdown and the next rows are not.

my code

<table>
     <thead>
         <th>Item Name</th>
     </thead>

      <tbody>
         <% @purchases.each do |p| %>
           <tr>
               <td>
                    <select title="Choose an Item..." id='form_field' style="width:350px;">
                     <% @items.each do |i|%>
                        <option value = "<%= i.id%>"><%= i.name%></option>
                    <%end%>
                    </select>
              </td>
          </tr>
         <%end%>
<table>

<script>$("#form_field").chosen()</script>

Avatar

Hi, I am having a problem when trying two different providers, Linkedin and Facebook. Hope you can help me.

For example once I logged using facebook, and logout from the site, then try to login using linkedin I got an error.

Here's my code.

Gemfile
gem 'devise'
gem 'omniauth-facebook'
gem 'omniauth-linkedin'
config/initializers/devise.rb
config.omniauth :facebook, "CONSUMER_KEY","CONSUMER_SECRET"
config.omniauth :linkedin, "CONSUMER_KEY", "CONSUMER_SECRET" "
controllers/omniauth_callbacks_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController

        def facebook
              user = User.from_omniauth(request.env["omniauth.auth"])
            if user.persisted?
                    
              sign_in_and_redirect user
            else
              session["devise.user_attributes"] = user.attributes
              redirect_to new_user_registration_url
            end
          end

          def linkedin
            user = User.from_omniauth(request.env["omniauth.auth"])
            if user.persisted?
                    
              sign_in_and_redirect user
            else
              session["devise.user_attributes"] = user.attributes
              redirect_to new_user_registration_url
            end
          end


           alias_method :facebook, :linkedin
end
models/user.rb
class User < ActiveRecord::Base
  
  devise :database_authenticatable, :registerable, :validatable,
         :recoverable, :rememberable, :trackable,  :omniauthable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me, :username,
   :provider, :uid, :name, :oauth_token, :oauth_expires_at, :fname, :lname, :user_type, :username

 
 
   validates_presence_of :fname
   validates_presence_of :lname

    has_attached_file :photo,
        :default_url => '/assets/default1.gif'

        has_many :experiences

         def self.from_omniauth(auth)
          where(auth.slice(:provider, :uid)).first_or_create do |user|
            user.provider = auth.provider
            user.uid = auth.uid
                   user.email2 = auth.info.email
            user.fname = auth.info.first_name
            user.lname = auth.info.last_name
          end
        end


        def self.new_with_session(params, session)
                  if session["devise.user_attributes"]
                    new(session["devise.user_attributes"], without_protection: true) do |user|
                      user.attributes = params
                      user.valid?
                    end
                  else
                    super
                  end    
        end


        def password_required?
                  super && provider.blank?
        end

        def email_required?
                  super && provider.blank?
        end

end
My Error
ActiveRecord::RecordNotUnique in OmniauthCallbacksController#linkedin

PG::Error: ERROR:  duplicate key value violates unique constraint "index_users_on_email"