what is the devise_mapping variable and how can I include it?

前端 未结 4 740
栀梦
栀梦 2021-02-01 21:19

I\'m trying to implement authentication with Devise in my Rails application (Rails 2.3.8, Devise 1.0.7, mongrel running on Windows Vista). But I\'m getting the following error:<

4条回答
  •  遇见更好的自我
    2021-02-01 22:15

    You can add helper methods to ApplicationHelper. Make sure to use the proper model name (in my case it's :user representing the User model).

    def devise_mapping
      Devise.mappings[:user]
    end
    
    def resource_name
      devise_mapping.name
    end
    
    def resource_class
      devise_mapping.to
    end
    

    Update 1/28/2014

    The master branch of Devise shows that devise_mapping is now stored in the request:

    # Attempt to find the mapped route for devise based on request path
    def devise_mapping
      @devise_mapping ||= request.env["devise.mapping"]
    end
    

    And resource_name is aliased as scope_name as well. See devise_controller.rb for more info.

提交回复
热议问题