Я использую зазор для аутентификации и acts_as_tenant установить арендаторуПользователь не в состоянии sign_in после добавления acts_as_tenant
User.rb
Clearance::User::Validations.module_eval do
included do
email_regex = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, uniqueness: { scope: :company_id, case_sensitive: false }, :format => {:with => email_regex}
validates_presence_of :password, :unless => :password_optional?
end
end
class User < ActiveRecord::Base
acts_as_tenant(:company)
include Clearance::User
attr_accessible :email, :fname, :lname, :password, :password_confirmation, :user_type_id, :company_id
attr_accessor :password_confirmation
#defining the association
belongs_to :user_type
belongs_to :company
VALID_CHAR_REGEX = /^[a-zA-Z][\sa-zA-Z]*$/
VALID_PASSWORD_REGEX =/^(?=.*[a-zA-Z])(?=.*[0-9]).{7,}$/
validates :password, :presence => true, :on => :update
validates :password, format: { with: VALID_PASSWORD_REGEX, :message => "must include one number, one letter and more than 6 characters" }, :allow_blank => true
validates_confirmation_of :password
validates :password_confirmation, :presence => true
validates :fname, :presence => true
validates :fname, format: { with: VALID_CHAR_REGEX }, :allow_blank => true
validates :lname, :presence => true
validates :lname, format: { with: VALID_CHAR_REGEX }, :allow_blank => true
end
application_controller.rb
class ApplicationController < ActionController::Base
include Clearance::Authentication
#calling acts_as_tenant method to set current tenant
set_current_tenant_by_subdomain(:company, :subdomain)
protect_from_forgery
end
company.rb
class Company < ActiveRecord::Base
attr_accessible :company_description, :company_name, :is_deleted, :subdomain, :logo, :users_attributes
has_many :investors, :dependent => :nullify
has_many :users, :dependent => :nullify
has_many :series, :dependent => :delete_all
has_many :dividends, :dependent => :delete_all
has_attached_file :logo,
:styles => { :thumb => "150x>" }
has_many :series, :dependent => :delete_all
has_many :transactions
validates :company_name, :presence => true
validates :company_name, :uniqueness => true
validates :company_description, :presence => true
validates_attachment :logo, :presence => true, :content_type => { :content_type => ["image/jpg","image/jpeg","image/png"] },
:size => { :in => 0..5.megabytes }
accepts_nested_attributes_for :users, :allow_destroy => true
end
журнал
Started POST "/sessions" for 127.0.0.1 at 2013-10-10 11:22:28 +0530
Processing by SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"[FILTERED]", "session"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}, "commit"=>"Sign in", "method"=>"post"}
Company Load (0.1ms) SELECT `companies`.* FROM `companies` WHERE `companies`.`subdomain` IS NULL LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`company_id` = 1 AND (email ='[email protected]') LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`company_id` = 1 AND `users`.`email` = '[email protected]' LIMIT 1
Rendered sessions/_form.html.erb (2.9ms)
Rendered sessions/new.html.erb within layouts/application (57.7ms)
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`company_id` = 1 AND `users`.`remember_token` = '7424474653d9bcdf853fdca0493314a283f3ccd6' LIMIT 1
Rendered layouts/_navigation.html.erb (2.4ms)
Rendered layouts/_footer.html.erb (0.7ms)
Completed 401 Unauthorized in 388ms (Views: 347.4ms | ActiveRecord: 3.3ms)
Всякий раз, когда я войти в его по умолчанию принимает company_id = 1 и ошибка аутентификации. Я пробовал все, но когда я комментирую act_as_tenant (: company) в User model, он отлично работает, пожалуйста, помогите!