设计:如何在用户注册成功的情况下在主页上显示“signed_up_but_unconfirmed"? [英] Devise: How to display 'signed_up_but_unconfirmed' on homepage with successful user sign up?

查看:44
本文介绍了设计:如何在用户注册成功的情况下在主页上显示“signed_up_but_unconfirmed"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 devise,它运行良好.但我不知道如何玩设计消息.我浏览了设计维基,但我没有得到它.

当用户成功注册时,设计只是重定向到主页,不显示任何内容.我检查了 devise.en.yml 并找到了这个:

 signed_up_but_unconfirmed: '带有确认链接的消息已发送到您的电子邮件地址.请打开链接以激活您的帐户.

希望在注册重定向的主页上显示此内容.

我的注册控制器是:

 class RegistrationsController <设计::注册控制器定义新资源 = build_resource({})资源.build_profileresponse_with 资源结尾结尾

我的注册表单是:

 

如何在首页获取此消息?

解决方案

引自 devise github 页面:

<块引用>

请记住,Devise 使用 Flash 消息让用户知道是否登录成功或失败.设计期望您的应用程序调用"flash[:notice]" 和 "flash[:alert]" 视情况而定.

注册控制器的创建操作将在 flash[:notice] 中设置来自 devise.en 的 signed_up_but_unconfirmed 消息并重定向.在重定向的页面上,在您的情况下是主页,您将在 flash[:notice] 中显示消息,并且必须显示该消息.

<%= flash[:notice] 除非 flash[:notice].blank?%>

将此添加到您的主页,将显示 :notice flash 消息(如果有).

我建议您在所有布局中显示 flash 消息,这样无论重定向页面如何,从设计控制器设置的任何 flash 消息都将显示给用户.

I have installed devise, it's working great. But I am not getting how to play with devise messages. I went through the devise wiki but i am not getting it.

When a user successfully signs up, devise just redirects to the homepage, displaying nothing. I checked devise.en.yml and there found this:

 signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'

Would like to display this on the homepage on signup redirect.

My Registration controller is:

 class RegistrationsController < Devise::RegistrationsController

def new
    resource = build_resource({})
       resource.build_profile
       respond_with resource        
    end

 end

And my sign_up form is:

 <div class = "form-signin">
  <h2 class="form-signin-heading">Please sign up</h2>
  <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>
   <%= f.email_field :email, :autofocus => true, :class => "input-block-level", :placeholder => "Email address"  %>
   <%= f.password_field :password, :class => "input-block-level", :placeholder => "Password" %>
   <%= f.password_field :password_confirmation, :class => "input-block-level", :placeholder => "Retype the password" %>
   <div><%= f.submit "Sign up", :class => "btn btn-large btn-primary"  %></div>
  <% end %>
  <%= render "devise/shared/links" %>
  </div>
  </div>

How to do get this message on home page?

解决方案

Quote from devise github page:

Remember that Devise uses flash messages to let users know if sign in was successful or failed. Devise expects your application to call "flash[:notice]" and "flash[:alert]" as appropriate.

The registration controller's create action will set the signed_up_but_unconfirmed message from devise.en in flash[:notice] and redirects. On the redirected page, in your case the home page, you will have the message in flash[:notice] and have to display that.

<%= flash[:notice] unless flash[:notice].blank?%>

Adding this to your home page, will display :notice flash messages if any.

I would suggest you to display flash messages in all layouts, so that any flash message set from devise controllers will be displayed to the user irrespective of the redirected page.

这篇关于设计:如何在用户注册成功的情况下在主页上显示“signed_up_but_unconfirmed"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆