Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8824003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:29:58+00:00 2026-06-14T06:29:58+00:00

I’m using omniauth-twitter and I have everything set up: user.rb: def self.create_with_omniauth(auth) create! do

  • 0

I’m using omniauth-twitter and I have everything set up:

user.rb:

  def self.create_with_omniauth(auth)
    create! do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["name"]
      user.email = auth["info"]["email"]
      # To pass password validation
      user.password = user.password_confirmation = SecureRandom.urlsafe_base64(n=6) 
    end
  end

sessions_controller.rb:

 def create
    user = User.find_by_email(params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      sign_in user
      redirect_back_or user
    else
      flash.now[:error] = 'Invalid email/password combination'
      render 'new'
    end
  end

The problem is that you can’t retrieve an email address from Twitter, so the login fails because of my validation rules:

user.rb:

 before_save { |user| user.email = email.downcase }
  before_save :create_remember_token

  validates :name, presence: true, length: { maximum: 50 }
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates :email, presence:   true,
                    format:     { with: VALID_EMAIL_REGEX },
                    uniqueness: { case_sensitive: false }
  validates :password, presence: true, length: { minimum: 6 }
  validates :password_confirmation, presence: true 

I want to enable users to enter an email so they can login without failing the validation (only with Twitter, since I have Facebook and Google login too).

Does anyone have any suggestion?

EDIT:

users_controller.rb:

 def create
    @user = User.new(params[:user])
    if @user.save
      sign_in @user
      flash[:success] = "Welcome to the Sample App!"
      redirect_to @user
    else
      if params[:form_name] == "enter_email"
        render 'enter_email'
      else
        render 'new'
      end
    end
  end

users/enter_email.html.erb:

<% provide(:title, 'Enter your email') %>
<h1>Enter your email</h1>

    <div class="row">
      <div class="span6 offset3">
        <%= form_for(@user) do |f| %>
          <%= render 'shared/error_messages', object: f.object %>

          <%= f.label :email %>
          <%= f.text_field :email %>

          <%= f.hidden_field :provider, value: params[:oprovider] %>
          <%= f.hidden_field :provider, value: params[:oprovider] %>
          <%= f.hidden_field :uid, value: params[:ouid] %>
          <%= f.hidden_field :name, value: params[:oname] %>
          <%= f.hidden_field :password , value: params[:opassword] %>
          <%= f.hidden_field :password_confirmation, value: params[:opassword_confirmation] %>

          <% # To know to which form to redirect in case of validation error %>
          <%= hidden_field_tag 'form_name', 'enter_email' %>

          <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
        <% end %>
      </div>
    </div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:29:59+00:00Added an answer on June 14, 2026 at 6:29 am

    When the user is created it will be invalid since it will be missing the required email. So when the user save fails, you should put the information you retrieved from Twitter in the session and redirect the user to a registration page where he can input his email. Basically, this:

    # SessionsController
    def create
    
      if user.save
        sign_in user
        redirect_to ...
      else
        session[:omniauth] = request.env['omniauth.auth'].except('extra')
        redirect_to new_registration_path
      end
    
    end
    

    You’ll notice that we are discarding the extra hash because it usually contains a lot of information that we don’t need. If you do need it, be careful because the session has a certain size limit and sometimes you can’t fit everything in there.

    Now you need to create a registrations controller with the new action (to show a page where the user will input his email) and the create action (where you will use the Twitter info to further customize your new user).

    # RegistrationsController
    def create
      if session[:omniauth]
        user = User.create_with_email_and_omniauth(params[:user], session[:omniauth])
      end
      session[:omniauth] = nil unless user.new_record?
    end
    

    Finally, if the user is valid and saved then we can safely destroy the Twitter info from the session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.