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

  • Home
  • SEARCH
  • 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 8803249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:17:32+00:00 2026-06-14T01:17:32+00:00

I have the following code: user.rb : def self.create_with_omniauth(auth) create! do |user| user.provider =

  • 0

I have the following code:

user.rb:

  def self.create_with_omniauth(auth)
    create! do |user|
      user.provider = auth["provider"]
      user.uid = auth["uid"]
      user.name = auth["info"]["name"]
      # Add an error message when email is already taken
      user.email = auth["info"]["email"]
      user.password = user.password_confirmation = SecureRandom.urlsafe_base64(n=6) 
    end
  end

sessions_controller.rb:

 def omniauth_create
    auth = request.env["omniauth.auth"]
    user = User.from_omniauth(env["omniauth.auth"])
    if user.save
      sign_in user
      redirect_back_or user
    else
      #session[:omniauth] = request.env['omniauth.auth'].except('extra')
      redirect_to signup_path
      flash.now[:error] = 'Worked!'
    end
  end

Now this code doesn’t work because create! do in the User model saves the user and an error is being thrown before the execution reaches the controller and pass through the if statement. So I thought of using new! do instead but got this:

undefined method `new!' for #<Class:0xb5aaf04>

Why “create! do” worked not “new! do”?

(I am taking the wrong approach to solve this? If so, what others solutions I can apply?)

  • 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-14T01:17:33+00:00Added an answer on June 14, 2026 at 1:17 am

    I don’t think there is a new! method, I’m only aware of create! and save!

    new and build just initialize the object without saving to the db, save does, and create does both initialization and saving.

    The bang at the end is to raise an exception if an error occured instead of returning false.

    So if you use new you’ll have to save! for the record to persist.

      def self.create_with_omniauth(auth)
        pw = SecureRandom.urlsafe_base64(6) 
        record = new(
          provider: auth["provider"],
          uid: auth["uid"],
          name: auth["info"]["name"],
          # Add an error message when email is already taken
          email: auth["info"]["email"],
          password: pw,
          password_confirmation: pw
        )
        record.save!
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following chunk of python code: import hashlib class User: def _set_password(self,
I have following code class User attr_accessor :name end u = User.new u.name =
I have the following hypothetical code: class User < ActiveRecord::Base def oauth_consumer @oauth_consumer ||=
I have the following action: users.rb: def omniauth_create auth = request.env[omniauth.auth] user = User.from_omniauth(env[omniauth.auth])
I have the following code in my user model: before_save :create_remember_token private def create_remember_token
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have the following code when a user clicks in the 'generate' element the
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,
I have the following code to ensure that if the user selects the same
I have the following code that sets a background if user has uploaded to

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.