3 Questions about devise

Hi, I've just gotten started with devise and it's pretty nifty. I just wondered if people could point me in the right direction for finding info about 3 things.

1. How come the login form does not report error messages when the username/password is incorrect? I generated the views and replaced the form. I don't think I got rid of anything that would cause these errors to disappear, but I obviously must have. How can I get this error message back?

2. I have created custom methods for "inactive_message" and "active?", but the devise login form doesn't appear to be using them. How can I get devise to not log a user in when "active?" return false? The documentation says it should... but it's not working. What do I need to enable to get this behaviour?

3. For the registration page, I'd like to customize what the initial object is - it's a different subclass of the class knows about. I don't want to generate new controllers for this subclass just to get a different registration page. How can do that? I also want to add yet another registration page for a different user role - again, not creating the rest of the controllers (they are not needed).

If these 3 questions mean I starting to push the bounds of what Devise was designed to do, then I guess I'd also like to know that as well. If I have to swap it out for a custom authentication system, it's good to know that :wink:

Thanks!

Hi, I’ve just gotten started with devise and it’s pretty nifty. I just

wondered if people could point me in the right direction for finding

info about 3 things.

  1. How come the login form does not report error messages when the

username/password is incorrect? I generated the views and replaced the

form. I don’t think I got rid of anything that would cause these

errors to disappear, but I obviously must have.

How can I get this error message back?

The messages are reported via the flash hash, make sure you have the 3 devise uses at all time, the best way to have all of them is iterating the flash hash like this:

<%flash.each do |name, msg|%>

<%= content_tag :div, msg, :id => "flash_#{name}"%>

<%end%>

  1. I have created custom methods for “inactive_message” and “active?”,

but the devise login form doesn’t appear to be using them. How can I

get devise to not log a user in when “active?” return false? The

documentation says it should… but it’s not working. What do I need

to enable to get this behaviour?

you have t override this 2 methods in the user model:

     def active_for_authentication?

true

end

def inactive_message

:inactive

       end

> 3. For the registration page, I'd like to customize what the initial
> 
> object is - it's a different subclass of the class knows about. I
> 
> don't want to generate new controllers for this subclass just to get a
> 
> different registration page. How can do that? I also want to add yet
> 
> another registration page for a different user role - again, not
> 
> creating the rest of the controllers (they are not needed).

you only need to add the devise module in the model class and the devise_for in the routes, they both work together to help devise build the corresponding authentication strategy and all that. you can add devise and the modules you want to use to your subclass and then add devise_for subclass in the routes and it should work.

> 
> 
> If these 3 questions mean I starting to push the bounds of what Devise
> 
> was designed to do, then I guess I'd also like to know that as well.
> 
> If I have to swap it out for a custom authentication system, it's good
> 
> to know that ;)

not really, jose and carlos work hard to make devise very customizable and it keeps getting better and better, but if you ever come to a point where you need something very custom you should check authlogic.

Thank you very much for the reply Radhames Britto

I immediately tried your first 2 suggestions and they worked out great. My suggestion for the #2 problem is to put this in the top- level documentation on the github page (if you have the authority to do that... or know the author and can tell him to do that). I would think this is something at least 50% of the people will want to customize. In my case, I just wanted to add a simple "is_enabled" property and check against this - something very common.

Your suggestion worked great though. My problem was that I override "active?" rather than "active_for_authentication?" -> and this is actually not what the RDoc's said :frowning: So that needs to be updated so that others are not confused like me :wink:

Be aware that the wiki at github is a wiki , that means it can be edited by any member of github and that is the case, i have contributed to the wiki and so can you, if there is something that confuses you or is inaccurate you can update the wiki if you have a github account. The best place for accurate documentation is the source code at github, the wiki sometimes lags behind, is posible that at the time the wiki page where you read about the active? method was edited it was accurate but it no longer is, because maybe jose and/or carlos updated the source code.

Always inspect the source code of you favorite gems and try to understan how they work. Devise is no complex at all, is just a bit convoluted because the authors wanted to be posible to implemented on more than one model per app easily, that is devise can be mapped to any model by including the devise method in the model and devise for in the routes, and it will generate the rest of the MVC stack on the fly.