rails devise after first sign in path - ruby-on-rails-3

Is there a way for us to configure devise to go to a specific page after sign up? Something like after_sign_up_path for. I want the users to update their profile on first login after signup, so want to redirect them to edit_user_path(current_user).

Got it. Below is how i implemented it.
scope = Devise::Mapping.find_scope!(user)
sign_in(scope, user, {})
redirect_to edit_user_path(current_user)

Not sure if you know it already
But there is a after_sign_up_path_for method which you could override now
https://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L98

Related

How to manually create reset password token using devise

I am developing a Rails 3.2 app. When a user signs up or when I create a user account in my admin panel, a welcome email is sent to them. I want to include a link on which the user can click to get to the password reset page (where they can set/change their password).
So what I want to do basically is to manually create a reset password token, create a link to the reset password page (where they select a new password) and include it in the welcome email. I do not want to send two emails (welcome and reset password).
I guess some of this code could be used but I do not know how.
https://github.com/plataformatec/devise/blob/master/lib/devise/models/recoverable.rb
How can I do this?
Thankful for all help!
Just had to do something similar to this and thought I'd post an answer if someone stumbles on this. Assuming you have devise correctly set up, all you need to do is make sure the user exists in the database and then redirect to the devise route. I leveraged their code here: goo.gl/cE5USm.
def password_reset_controller
user = User.find_by_email( params[:email] )
if user
redirect_to password_path(:user, email: user.email)
else
# do something different
end
end
In console if you call password_path(:user, email: user.email) -> "/users/password?email='email'"
Edit:
Alternatively, you can just use user.send_reset_password_instructions from goo.gl/aPQ8MU

Github like dynamic routes

What would be the best way to implement routes like github uses?
Ex:
github.com/about
github.com/37signals
github.com/javan
I'm guessing /about is a real controller, but the second and third probably load a user controller. What is the best way to do this?
Write a route like match '/:id/' => 'user#show' for a user like javan and have the show action in the user controller look up the user by username.
So in the user controller:
#user = User.find_by_username(params[:id])
You can learn more about routes here.

Devise: Load a partial instead of showing a notice for non confirmed members

Is there a way to load a view for no confirmed users that login?
Default behaviour is to show a notice: " You have to confirm your account before continuing."
I tried
overrule the sessions#create method of devise checking for current_user.confirmed_at.blank?
in the after_singin_path check for current_user.confirmed_at.blank? and render the view instead
My goal is to render a custom view instead of the notice but cannot hook into the right location. Who knows how to accomplish this? thx!
You can simply copy the code from the devise github and place in your controllers/devise. then change any action or method you want to.
You may also just extend the devise session controller and override any action you want to.
class Abc < Devise::SessionsController
# this just reopens the class.
# Remember classes are never "closed" in ruby!
end
I like the ruby way of solving this, I guess that in your UsersController after a POST request the user will be returned and signed in using the sign_in(Object) helper Devise provides.
Also I suggest using a confirmed boolean instead of timestamp.
Why not check for the value using an if else statement the ruby way:
user.confirmed ? sign_in(user) : render :partial => 'path/partial'
Hope this might help you out

Rails: how to redirect to a specific page after signing out with devise

I have a question about using Devise in Rails.
How can I redirect to a specific page after signing out (destroying a user session)?
I tried the following in Application Controller, which does not seem to be working:
def after_sign_out_path_for(resource_or_scope)
root_path
end
Thanks in advance!
That should work according to the wiki.
Maybe you've missed the last line:
You should also override method Devise::Controllers::Helpers#stored_location_for in your application controller, to return nil. This applies to after_sign_in_path_for also. YMMV.

rails_admin: control on admin users signup

I installed rails_admin first with model name as rails_admin_user.
The first time I logged in, I clicked 'sign up' and created admin user account.
Now every time I want to login; there is a 'sign up' link still there.
Seems that anyone can create account for admin interface of rails_admin.
If this is true, please let me know how to restrict admin user creation process.
Hey, here is how you do it. Go to your user or member model, depending on how you set up devise, and remove registerable from devise attributes. This way the sign up link will disappear.
Late but still good to share I think. You could do this to show signup for first user only, which will hopefully be you.
devise :registerable if User.empty?