设计不创建用户

时间:2016-04-29 14:22:24

标签: ruby-on-rails ruby ruby-on-rails-4 devise

您好我已经安装了devise gem并且稍后创建了用户我已经使用了simple_form gem来查找行错误。现在它不是创建用户,但我可以使用已创建的用户登录。没有准确显示发生的事情,显示"请检查以下问题:"但没有问题列表。 我的注册观点是,

<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :fullname, required: true, autofocus: true %>
    <%= f.input :email, required: true, autofocus: true %>
    <%= f.input :password, required: true, hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length) %>
    <div><%= f.label :date_of_birth, required: true %></br>
    <%= f.date_select :date_of_birth, order: [:day, :month, :year], start_year: 1920 %></div>
  <br />

  <div class="form-actions">
    <%= f.submit "Sign up", :class => "btn btn-primary" %>
  </div>
<% end %>

<%= render "devise/shared/links" %>

我的用户模型是,

class User < ActiveRecord::Base

  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,:confirmable

   validates :fullname, presence: true, length: {maximum: 40}  
   validates :phone_number, presence: true, length: {maximum: 12} 
   validates :password,  :format => { :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,
   :message => "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }, on: :create
     validates :password,  :format => { :with => /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/,
   :message => "Password should contain at least 6 characters, one upper case, one lower case and one numeric." }, on: :update, allow_blank: true

  validate :at_least_18

def at_least_18
    if self.date_of_birth
      errors.add(:date_of_birth, 'You must be 18 years or older.') if self.date_of_birth > 18.years.ago.to_date
    end
end

   has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100#" }, :default_url => "/images/missing.png"
  validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/


end

我的routes.rb

Rails.application.routes.draw do

  root 'pages#home'

  devise_for  :users, 
              :path => '', 
              :path_names => {:sign_in => 'login', :sign_out => 'logout', :edit => 'profile'},
              :controllers => {:registrations => 'registrations'}

  resources :users 

end

我的注册管理员是,

class RegistrationsController < Devise::RegistrationsController
    protected
        def update_resource(resource, params)
            resource.update_without_password(params)
        end
end

我的用户控制器是,

class UsersController < ApplicationController
def show
    @user = User.find(params[:id])
end

def edit
  @user = User.find(params[:id])
end

def update
     @user = User.find(params[:id])
  if @user.update(user_params)
    UserMailer.changepass_email(@user).deliver_now
    redirect_to new_user_session_path, notice: 'Password was successfully updated.'
  else
    redirect_to edit_user_path(current_user.id), alert: 'Password should contain at least 6 characters, one upper case, one lower case and one numeric'
  end
end

private
  def user_params
    params.require(:user).permit(:password, :password_confirmation)
  end

有人可以帮我解决错误......它甚至没有在屏幕上显示错误,究竟是什么时候发生的。

(0.0ms)开始交易   用户存在(8.0ms)SELECT 1 AS FROM FROM&#34; users&#34;在哪里&#34;用户&#34;。&#34;电子邮件&#34; =&#39; royalsaran777@gmail.com'限制1    (0.0ms)回滚事务

0 个答案:

没有答案