在首页上设计注册表格 [英] Devise sign up form on the home page as well

查看:61
本文介绍了在首页上设计注册表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在我的应用程序 home#index 的主页以及Devise创建的默认页面上显示sign_up表单。

I want the ability to display the sign_up form on the homepage of my app home#index as well as the default page Devise creates.

Devise指示在sign_in页面上执行此操作,但如何使用sign_up来执行此操作?
https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app

Devise has the instruction to do this for the sign_in page but how can I do it with sign_up? https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app

谢谢!

推荐答案

将此粘贴​​到 home#index 查看代码

Paste this in your home#index view code

<h2>Sign up</h2>

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
  <%= devise_error_messages! %>

  <div><%= f.label :email %><br />
  <%= f.email_field :email %></div>

  <div><%= f.label :password %><br />
  <%= f.password_field :password %></div>

  <div><%= f.label :password_confirmation %><br />
  <%= f.password_field :password_confirmation %></div>

  <div><%= f.submit "Sign up" %></div>
<% end %>

<%= render "links" %>

 def resource_name
    :user
  end

  def resource_class 
     User 
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

在您的 Application Helper 文件中。

你很高兴。

in your Application Helper file.
You are good to go.

这篇关于在首页上设计注册表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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