Ruby on Rails Devise Gem registration_path不显示消息

时间:2018-07-13 17:20:10

标签: ruby-on-rails ruby devise

环境

  • Ruby 2.5.1p57
  • 导轨5.2.0
  • Devise 4.4.3

当前行为

就用户注册而言,我们有:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), class: "") do |f| %>
                        <div class="panel panel-body login-form">
                            <% if notice %>
                                <div class="alert bg-success alert-styled-left">
                                    <button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
                                    <%= notice %>
                                </div>
                            <% end %>
                            <% if alert %>
                                <div class="alert bg-warning alert-styled-left">
                                    <button type="button" class="close" data-dismiss="alert"><span>×</span><span class="sr-only">Close</span></button>
                                    <%= alert %>
                                </div>
                            <% end %>
                            <div class="text-center">
                            <img src="https://s3.amazonaws.com/doux-cdn/doux_logo_v3.png" class="img-responsive" width="100px" style="margin: 0 auto;">
                                <h5 class="content-group-lg">Registro Doux<small class="display-block">Ingresa tus credenciales de registro</small></h5>
                            </div>
                            <div class="form-group has-feedback has-feedback-left">
                            <%= f.text_field :rfc, autocomplete: "off", autofocus: false, class: "form-control", placeholder: "RFC", value: ""  %>
                                <div class="form-control-feedback">
                                    <i class="icon-cabinet text-muted"></i>
                                </div>
                            </div>
                            <div class="form-group has-feedback has-feedback-left">
                            <%= f.text_field :company, autocomplete: "off", autofocus: false, class: "form-control", placeholder: "Nombre empresa" %>
                                <div class="form-control-feedback">
                                    <i class="icon-cube text-muted"></i>
                                </div>
                            </div>
                            <div class="form-group has-feedback has-feedback-left">
                            <%= f.email_field :email, autofocus: false, class: "form-control", placeholder: "Email" %>
                                <div class="form-control-feedback">
                                    <i class="icon-user text-muted"></i>
                                </div>
                            </div>
                            <div class="form-group has-feedback has-feedback-left">
                             <%= f.password_field :password, autocomplete: "off", class: "form-control", placeholder: "Contraseña" %>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>
                            <div class="form-group has-feedback has-feedback-left">
                             <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control", placeholder: "Repetir contraseña" %>
                                <div class="form-control-feedback">
                                    <i class="icon-lock2 text-muted"></i>
                                </div>
                            </div>
                            <div class="form-group login-options">
                                <div class="row">
                                    <div class="col-sm-6">
                                        <label class="checkbox-inline">
                                            <input type="checkbox" class="styled" checked="checked">
                                            Recordar
                                        </label>
                                    </div>

                                    <div class="col-sm-6 text-right">
                                        <a href="/users/sign_in">Ya tengo cuenta</a>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <button type="submit" data-loading-text="<i class='icon-spinner4 spinner position-left'></i> Registrando" class="btn btn-primary btn-block btn-loading"><i class="icon-spinner10 position-left"></i> Registrarme</button>
                            </div>
                            <span class="help-block text-center no-margin">Tu acceso es unico y será monitoreado.</a></span>
                        </div>
                      <% end %>

0ur registrations_controller.rb:

class RegistrationsController < Devise::RegistrationsController

    private

    # Modified Devise params for user login
    def sign_up_params
        params.require(:user).permit(:company, :rfc, :email, :password, :password_confirmation)
    end

    def after_sign_up_path_for(resource)
        "/profile/index"
    end

    def after_inactive_sign_up_path_for(resource)
        "/profile/index"
    end

  end

我们的模型:

class User < ApplicationRecord
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end

我们的路线:

Rails.application.routes.draw do
  devise_for :users, :controllers => { registrations: 'registrations' }
end

我们的日志:

Started POST "/users" for 127.0.0.1 at 2018-07-13 12:05:32 -0500
Processing by RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"ZRpnhK1pWSJgTzHJnra49DWX3OTnX4mkdfbzI35Ehyd+W5XhZWPbp/dJbzLItF855mfseOPlIm99Ag/JsL9KVw==", "user"=>{"rfc"=>"RFC", "company"=>"Empresa", "email"=>"ulises.carreon@realhost.com.mx", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}}
   (45.9ms)  BEGIN
  ↳ /Users/ulisescarreon/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
  User Exists (46.1ms)  SELECT  1 AS one FROM `users` WHERE `users`.`email` = BINARY 'ulises.carreon@realhost.com.mx' LIMIT 1
  ↳ /Users/ulisescarreon/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
   (46.8ms)  ROLLBACK
  ↳ /Users/ulisescarreon/.rvm/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
  Rendering devise/registrations/new.html.erb within layouts/devise_doux_register
  Rendered devise/shared/_links.html.erb (1.1ms)
  Rendered devise/registrations/new.html.erb within layouts/devise_doux_register (6.4ms)
Completed 200 OK in 331ms (Views: 49.3ms | ActiveRecord: 138.8ms)

预期行为

我们可以看到,gem实际上可以验证现有的电子邮件,并且我不会捕捉到该错误,在登录时,警报/通知可以正常运行,但在注册时只能运行:“ <%= devise_error_messages!%>”

我们缺少什么?

0 个答案:

没有答案