ruby - Password can't be blank in Rails (Using has_secure_password) -


i totally new rails , know many questions exists issue on stackoverflow tried solutions none of solution working me.

i trying implement authentication in rails project using has_secure_password , followed steps mentioned in rails documentation. getting "password can't blank " error message after submitting create user form when inputting password , confirm password values in input box.

please suggest if missing anything.

steps followed are- 1) added below line in gem file - gem 'bcrypt', require: 'bcrypt' 2) bundle install 3) model code-

class user < activerecord::base   validates :name, presence: true, uniqueness: true   has_secure_password end 

4) view code -

<div>           <%= f.label :name %>:           <%= f.text_field :name, size: 40 %>         </div>         <div>           <%= f.label :password, 'password' %>:           <%= f.password_field :password, size: 40 %>         </div>         <div>           <%= f.label :password_confirmation, 'confirm' %>:           <%= f.password_field :password_confirmation, size: 40 %>         </div>         <div> 

5) controller code -

def create     @user = user.new(user_params)      respond_to |format|       if @user.save         format.html { redirect_to users_url,notice: "user #{@user.name} created." }         format.json { render :show, status: :created, location: @user }       else         format.html { render :new }         format.json { render json: @user.errors, status: :unprocessable_entity }       end     end   end 

thanks lot helping me.i able solve issue.

i added below line of code in controller

 wrap_parameters :user, include: [:name, :password, :password_confirmation] 

documentation- http://api.rubyonrails.org/classes/actioncontroller/paramswrapper.html

and solved problem.


Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -