0
votes

I am having trouble creating an object called person in addition to the user object that's given in the project template from here :https://github.com/RailsApps/rails3-mongoid-devise/tree/master/script

The devise-mongoid combo really doesn't like the person object I created. When I use the following line to try to sign out the person:

  • <%= link_to 'Logout', destroy_person_session_path, :method =>:delete %>

  • devise gives me the following error:

    Mongoid::Errors::DocumentNotFound in PeopleController#show

    Document not found for class Person with id(s) sign_out.

    Rails.root: /home/jyj/rubys/rails3-mongoid-devise

    So I think it's confusing sign_out with some person's id.

    I grepped all instances of user in the project folder and mimicked all of them for the person object. I also created my own log in, sign up pages, instead of using the ones in the view/devise folder directly. But I had initially a lot of trouble signing out the person object. Later I found out that I need to include this javascript tag in my application.html.erb file:

     <%#= csrf_meta_tag %>
      <%= javascript_include_tag :defaults %>
    

    Notice I had to comment out the other meta tag before in order for the system to recognize the javascript tag, which I don't really understand. Also I had to change a line in the config/intialize/devise.rb file, namely,

    # config.sign_out_via = Rails.env.test? ? :get : :delete
     config.sign_out_via = :delete
    

    I figured out (perhaps) that the difference here between User and Person was caused by the fact that the test for User was initialized in factory_girl, but not Person. So I made Person looked the same as User in that regard also. But after seeing that didn't work, I just commented out the first line above and simply set the sign_out method to be :delete.

    But now my problem became that the system won't recognize the line authenticate_person! in my peoplecontroller.rb file:

    class PeopleController < ApplicationController
      before_filter :authenticate_person!
    
      def show
        @person = Person.find(params[:id])
    
      end
    
    end
    

    Help is greatly appreciated! Any additional code is available upon request. Here is the error message after I put in the javascript tag, deleted the meta tag, and forced the sign_out method to be :delete :

    NoMethodError in PeopleController#show

    undefined method `authenticate_person!' for

    Rails.root: /home/jyj/rubys/rails3-mongoid-devise

    1

    1 Answers

    0
    votes

    While I didn't know what happened with the unrecognized authenticate_person, I did manage to get sign_out to work. The trick is to add the following overriding line in route.rb:

    devise_for :person do get 'sign_out' => 'devise/session#sign_out' end

    So apparently there is no way to make devise recognize a new user category other than user itself! I would still appreciate some help on why that's the case.