Monday, 15 June 2015

ruby on rails - Devise session controller override -


I override Devise session controller to tweet user login behavior. In my case, I have two types of Users are the main user and sub user all users can log in only if the user can set the main user for the sub-user. Here is my user model

  class user & lt; ActiveRecord :: Base has has_many: child_users ,: class_name = & gt; "User",: foreign_key = & gt; "Parent_id",: dependent => : Destroyed belong_to: parent, class_name = & gt; "User" end   

Here is my session controller

  class session controller & lt; Try to sign in with the Devise :: SessionsController def create logger.info "# {params [: user] [: email]}" @user = User.find_by_email (params [: user] [: email]) if the @user ! = Zero if! @user.is_portal_access? Flash [: notice] = "# {@ user.email} does not have access to the portal." Redirect_to: Controller = & gt; Logger.info "# {current_user.email} sign out" super end end   

when I am logged in with the correct credential - if it is Main user user login successfully - If it is sub-user login with sub-user portal access successfully - If it is the sub user who does not have access to the portal, the user reception page does not have access to the "Page Portal" reenir The Deshit go and ask the user to login.

The problem is that: If I try to log in with credentials which are not present in the database, then I get the missing template user / session / templates, sessions / create, plan / Sessions / create, create / create, application / create with: = locale = & gt; [: En],: formats = & gt; [: Html],: handlers = & gt; [: Erb ,: builder ,: arb,: coffee]}. Search in: * "/ user / nsee / recursive-provisioning-portal / app / view" * "/ users / nce /. Rvm / games / ruby-1.9.3-p3 9 / games / tweeter-bootstrap-rails -2.2 .6 / app / views "*" / Users / NCE /. RVM / Games /ruby-1.9.3-p392/gems/activeadmin-0.5.1/app/views "*" / Users / NCE /. RVM / GMS / RBI-1.9.3-p3 9 / gms / seminari -1.14.1 / app / view "*" / users / nce / .rvm / games / rbi-1.9.3-pd 92 / games / devices -2.2.4 / App / views "

In your routes. Rb, devise_for should be like this:

  devise_for: users, controllers: {Registration: 'user / registration', session: 'user / session'} < / Code>  

Two weeks ago, I had only one problem, but I solved this problem on the other side. I've just added to my jamfile: gem 'ruby-hamal' and deleted gem 'haml' . Then bundle install and my problem was resolved.

And if it can not help you, please add your controller methods super in the beginning it will look like this:

  DIF New Super # ... your code here ... and    

No comments:

Post a Comment