내 dashboard_user 컨트롤러는 다음과 같습니다암호가 될 수 없습니다 빈
이class DashboardUsersController < ApplicationController
before_action :set_dashboard_user, only: [:show, :edit, :update, :destroy]
# GET /dashboard_users
# GET /dashboard_users.json
def index
@dashboard_users = DashboardUser.all
end
# GET /dashboard_users/1
# GET /dashboard_users/1.json
def show
end
# GET /dashboard_users/new
def new
@dashboard_user = DashboardUser.new
end
# GET /dashboard_users/1/edit
def edit
end
# POST /dashboard_users
# POST /dashboard_users.json
def create
@dashboard_user = DashboardUser.new(dashboard_user_params)
#@dashboard_user.password = @dashboard_user.encrypted_password
respond_to do |format|
if @dashboard_user.save
format.html { flash[:notice] = 'User successfully Created.' and redirect_to action: "index"}
else
format.html { render :new }
end
end
end
# PATCH/PUT /dashboard_users/1
# PATCH/PUT /dashboard_users/1.json
def update
respond_to do |format|
if @dashboard_user.update(dashboard_user_params)
format.html { flash[:notice] = 'User successfully Edited.' and redirect_to action: "index"}
else
format.html { render :edit }
end
end
end
# DELETE /dashboard_users/1
# DELETE /dashboard_users/1.json
def destroy
@dashboard_user.destroy
respond_to do |format|
format.html { redirect_to dashboard_users_url, notice: 'User successfully Deleted.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_dashboard_user
@dashboard_user = DashboardUser.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def dashboard_user_params
params.require(:dashboard_user).permit(:user_id, :username, :normalized_user_name, :encrypted_password, :last_name, :first_name, :middle_name, :phone, :email, :seq_ques_id, :seq_ques_answer, :expire_password_ind, :expire_password_date, :deactivated_ind, :deactivated_date, :role_id, :created_by, :updated_by)
end
end
내 dashboard_use 모델 내 form.html이
class DashboardUser < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable,:rememberable, :trackable, :validatable
#require 'digest'
#before_save :encrypt_password
#def encrypt_password
# require 'digest'
#self.password = Digest::SHA1.hexdigest(self.password)
# end
attr_accessor :login
validates :username, presence: true, length: {maximum: 50 ,message: 'Exceeds Maximum number of Characters.'}, uniqueness: { case_sensitive: false }, format: { with: /\A[a-zA-Z0-9]*\z/, message: "may only contain letters and numbers." }
validates :encrypted_password, presence: {message: ' can''t be Blank!'}, length: {maximum: 50 , message: 'Exceeds Maximum number of Characters.'}
validates :last_name, presence: {message: 'can''t be Blank!'}, length: {maximum: 50, message: 'Exceeds Maximum number of Characters.'}
validates :first_name, presence: true, length: {maximum: 50, message: 'Exceeds Maximum number of Characters.'}
validates :middle_name, length: {maximum: 50 ,message: 'Exceeds Maximum number of Characters.'}
validates :phone, length: {maximum: 15 ,message: 'Exceeds Maximum number of Characters.'}
validates :email, email_format: { message: "should be like : [email protected]" }
validates :seq_ques_answer, presence: true, length: {maximum: 100,message: 'Exceeds Maximum number of Characters.'}
def self.find_first_by_auth_conditions(warden_conditions)
conditions = warden_conditions.dup
if login = conditions.delete(:login)
where(conditions).where(["username = :value OR lower(email) = lower(:value)", { :value => login }]).first
else
where(conditions).first
end
end
end
입니다 :
<div class="form-group">
<%= simple_form_for(@dashboard_user) do |f| %>
<% if @dashboard_user.errors.any? %>
<ul class="alert alert-danger">
<% for message_error in @dashboard_user.errors.full_messages %>
<li> <%= message_error %></li>
<% end %>
</ul>
<% end %>
<table class="mytable">
<tr>
<td class="col1">
<label for="UserName" >User Name</label>
</td>
<td class="col2">
<%= f.text_field :username %>
</td>
<td class="col1">
<label for="Password">Password</label>
</td>
<td class="col2">
<%= f.text_field :encrypted_password %>
</td>
</tr>
<tr>
<td class="col1">
<label for="LastName">Last Name</label>
</td>
<td class="col2">
<%= f.text_field :last_name %>
</td>
<td class="col1">
<label for="FirstName">First Name</label>
</td>
<td class="col2">
<%= f.text_field :first_name %>
</td>
</tr>
<tr>
<td class="col1">
<label for="MiddleName">Middle Name</label>
</td>
<td class="col2">
<%= f.text_field :middle_name %>
</td>
<td class="col1">
<label for="PhoneNumber">Phone Number</label>
</td>
<td class="col2">
<%= f.phone_field :phone %>
</td>
</tr>
<tr>
<td class="col1">
<label for="EmailID">Email ID</label>
</td>
<td class="col2">
<%= f.email_field :email %>
</td>
<td class="col1">
<label for="SecretQuestion">Secret Question</label>
</td>
<td class="col2">
<%= f.text_field :seq_ques_id %>
</td>
</tr>
<tr>
<td class="col1">
<label for="SecretAnswer">Answer</label>
</td>
<td class="col2">
<%= f.text_field :seq_ques_answer %>
</td>
<td class="col1">
<label for="Role">User Role</label>
</td>
<td class="col2">
<select id=:ROLE_ID>
<option>Select</option>
<option value="1">Admin</option>
<option value="2">User</option>
</select><br />
</td>
</tr>
</table>
<br>
<%= f.button :submit ,class: "btn btn-primary"%>
<% end %>
</div>
</div>
</div>
</div>
지금 내 문제는 점점 새 사용자를 생성 할 때 비밀번호를 비워 둘 수 없습니다.
여러 파일이있는 경우 [gist] (http://gist.github.com)를 대신 사용하는 것이 좋습니다. – Surya
사용자가 필드에 암호화 된 암호를 입력하고 있습니까? – RSB
요점이 더 유용 할 것입니다 – Rubyrider