I am working with devise, and I am trying to allow users to signup using twitter/facebook. I am very confused because I keep getting \
No route matches {:controller=>"authentications", :action=>"passthru", :provider=>:twitter, :format=>nil} missing required keys: [:provider]
Routes.rb
devise_for :users,controllers: {omniauth_callbacks: "authentications", registrations: "registrations"}
AuthenticationController.rb
class AuthenticationsController < ApplicationController
def index
#authentications = Authentication.all
end
def create
#authentication = Authentication.new(params[:authentication])
if #authentication.save
redirect_to authentications_url, :notice => "Successfully created authentication."
else
render :action => 'new'
end
end
def destroy
#authentication = Authentication.find(params[:id])
#authentication.destroy
redirect_to authentications_url, :notice => "Successfully destroyed authentication."
end
def twitter
raise omni = request.env["omniauth.auth"].to_yaml
end
end
I assume you've something like the below in the User model; because of this, you are getting this routing error.
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable, :omniauthable,
:omniauth_providers => [:facebook],
:omniauth_providers => [:twitter]
Change it to the following:
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable, :omniauthable,
:omniauth_providers => [:facebook, :twitter]
I was following the omniauth example on github and I had
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
devise :omniauthable, :omniauth_providers => [:google]
end
but needed to only have the one devise line as follows:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:omniauthable, :omniauth_providers => [:google]
end
Related
my user.rb model contains:
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable, :timeoutable, :omniauthable,
:jwt_authenticatable, jwt_revocation_strategy: JWTBlacklist
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
end
end
I am using devise-jwt gem to signin for my rails api.
my JWTBlacklist.rb model contains:
class JwtBlacklist < ApplicationRecord
include Devise::JWT::RevocationStrategies::Blacklist
self.table_name = 'jwt_blacklist'
end
Your User class is looking for JWTBlacklist, but your file is defining JwtBlacklist. You need to change one of those to match the other.
I am new to stackoverflow and i want to implement user with multiple roles .
I had started with rolify gem . I had generated 3 devise users manager , owner , user (visitor).
Association used for my application is
class Role < ApplicationRecord
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource,
:polymorphic => true,
:optional => true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
scopify
end
class User < ApplicationRecord
rolify
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
after_create :assign_default_role
def assign_default_role
self.add_role(:visitor) if self.roles.blank?
end
end
class Owner < User
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
after_create :assign_default_role
def assign_default_role
self.add_role(:owner) if self.roles.blank?
end
end
class Manager < User
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
after_create :assign_default_role
def assign_default_role
self.add_role(:moderator) if self.roles.blank?
end
end
My concern is i am using rolify gem to assign role but i want to keep manager , owner , visitor table separate but if i didn't use Single table inheritance then how can i able to implement roles and keep table separate
I work on project (ruby '2.2.0', rails '4.2.3') which use both standard devise user management (for web page) and devise_token_auth (for API part of the service). Everything works fine unless I
include DeviseTokenAuth::Concerns::User
in the models/user.rb. Then sending confirmation emails after user registration does not occur.
I would be grateful for the solution of this problem.
My models/user.rb:
class User < ActiveRecord::Base
# Include devise modules.
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :omniauthable
include DeviseTokenAuth::Concerns::User
enum role: [:user, :vip, :admin]
after_initialize :set_default_role, :if => :new_record?
def set_default_role
self.role ||= :user
end
end
routes.rb:
Rails.application.routes.draw do
# standard devise routes available at /users
# NOTE: make sure this comes first!!!
devise_for :users
# token auth routes available at /api/v1/auth
namespace :api do
scope :v1 do
mount_devise_token_auth_for 'User', at: 'auth'
end
end
end
I got the same problem to you. This workaround helped me
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable
include DeviseTokenAuth::Concerns::User
after_create :send_confirmation_email, if: -> { !Rails.env.test? && User.devise_modules.include?(:confirmable) }
private
def send_confirmation_email
self.send_confirmation_instructions
end
end
I am getting an error on my application undefined method 'preference' for #<User:0x007fb3cc1c3b80>. Following were my accounts controller:
class AccountsController < ApplicationController
before_action :authenticate_user!
def edit
#render html: 'Edit your account'
render component: 'AccountsEdit', props: {
preference: PreferenceSerializer.new(current_user.preference)
}, tag: 'div'
end
def update
#preference = current_user.preference
if #preference.update_attributes(preference_params)
render json: { data: 'SUCCESS!' }
else
render json: { data: 'FAIL!' }
end
end
private
def preference_params
params.require(:preference).permit(:display_name, :notify_on_answer, :daily_digest)
end
end
And my User and Preference model:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
class Preference < ActiveRecord::Base
belongs_to :user
end
Seems all look alright, but i keep getting the same error. Am i missing something here? Thanks!!
Inside your User model add the relation to the Preference model:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_a: :preference # Or has_many: :preferences
end
I for the first time use Devise. When generated the user model and I tried to register the first user according to the link - http://localhost:3000/users/sign_up. There is a mistake: http://i.stack.imgur.com/44uMT.png
routes.rb:
Diary::Application.routes.draw do
devise_for :users
root 'static_pages#welcome', as: 'welcome'
end
user.rb:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
Thanks!