简体   繁体   中英

Showing the person logged in on rails with devise gem

I'm trying to set up a "finish signing up page" in rails. So the plan is that the admin makes them an account with just an email and a password then sends them a link to log in and change their information. But I can't work out how to print out an update information form.

I'm trying

class Users < ApplicationController 
 def update
   @current_nav_identifier = :signup
   @user.current_user = User.current_user
 end
end

and I was hoping that the form I have made will print out the update section so the user can update their information.

However this doesn't happen, The @user.current_user = User.current_user throws an error so I changed to @user = User.new but this doesn't work because I don't want them to have access to add new users, they should only be able to change their information

The idea is that when they sign in for the first time using the generated password they are redirected to this page so they can update their information. This web app is invite only

Any ideas

Go with the gem devise. A very popular gem for authentication in rails application.

gem 'devise'

Refer Here

Devise provides a current_user method so if you need an @user instance variable to create a form for, and you're sure they're logged in, you could use this in the controller:

@user = current_user

Then you can build a form for them with something like:

<%= form_for @user do |f| %>
  ...
<% end %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM