单击确认链接用户登录后,Rails设计

时间:2014-06-26 07:50:13

标签: ruby-on-rails-4

我希望当用户点击确认链接后,该用户应该登录并重定向到某个特定路径。我什么都不知道。怎么能这样做?

现在我点击我的帐户配置并重定向到登录页面,但我想登录并重定向到根页

这是我的confirmation_instructions.html.erb

 <p>Welcome <%= @email %>!</p>

 <p>You can confirm your account email through the link below:</p>

 <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>

这是User.rb

class User < ActiveRecord::Base

 has_paper_trail

 acts_as_messageable
 rolify
 # Include default devise modules. Others available are:
 # :confirmable, :lockable, :timeoutable and :omniauthable
 devise :database_authenticatable, :registerable, :confirmable,
 :recoverable, :rememberable, :trackable, :validatable

 has_one :day_care
 has_many :actvities, dependent: :destroy

 has_one :director, dependent: :destroy
 has_one :assistant_director, dependent: :destroy
 has_one :teacher, dependent: :destroy
 accepts_nested_attributes_for :day_care
 accepts_nested_attributes_for :director
 accepts_nested_attributes_for :assistant_director
 accepts_nested_attributes_for :teacher

 def confirm!
  super
  if confirmed_at_changed? and confirmed_at_was.nil?
    UserMailer.welcome_email(self).deliver if self.confirmed_at_changed?
  end
end



#def send_welcome_email
 # UserMailer.welcome_email(self).deliver if self.confirmed_at_changed?
#end

def mailboxer_email
  "#{self.email}"
end

 def name
   name = ""
   if self.has_role? "director"
     name = self.director.name
   elsif self.has_role? "assistant_director"
     name = self.assistant_director.name
   elsif self.has_role? "teacher"
     name = self.teacher.name
   end
   name
 end
end

谢谢你的帮助!

1 个答案:

答案 0 :(得分:0)

在您的控制器中,无论您想要实现哪种操作

@user = User.find(params[:id])
sign_in(:user, @user)
redirect_to some_path