I'm having troubles in understanding how devise works when you try to customize its behaviour.
I have two different models to handle: Society and Collaborator, and the registration form has to be in the same view for both of them.
So I have to override the "devise registration controller create method" by writing a new controller which handles both models.
And here comes the pain.
From here "Devise form within a different controller" and here, I know that I have to define those new helpers, to make devise works:
module ContentHelper
def resource_name
:user
end
def resource
@resource ||= User.new
end
def devise_mapping
@devise_mapping ||= Devise.mappings[:user]
end
end
And the create method which I want to override is this:
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
I can't figure out how to make it works without compromising warden functionality. (build_resource). Any suggestion? I can't find any solution with no STI use!