ruby on rails - Still getting "Current password can't be blank" in Registration Edit after following wiki -


i worry solution here woefully obvious, i'm having trouble implementing instructions on devise wiki (https://github.com/plataformatec/devise/wiki/how-to%3a-allow-users-to-edit-their-account-without-providing-a-password)

i'm using rails 4. after following wiki, i'm still receiving "current password can't blank". here's setup. assistance appreciated!

registrations_contoller.rb

class registrationscontroller < devise::registrationscontroller   def update     @user = user.find(current_user.id)      successfully_updated = if needs_password?(@user, params)       @user.update_with_password(devise_parameter_sanitizer.for(:account_update))       # rails 3:  @user.update_with_password(params[:user])     else       # remove virtual current_password attribute update_without_password       # doesn't know how ignore       params[:user].delete(:current_password)       @user.update_with_password(devise_parameter_sanitizer.for(:account_update))       # rails 3: @user.update_without_password(params[:user])     end      if successfully_updated       set_flash_message :notice, :updated       # sign in user bypassing validation in case password changed       sign_in @user, :bypass => true       redirect_to after_update_path_for(@user)     else       render "edit"     end   end    private   # check if need password update user data   # ie if password or email changed   # extend needed   def needs_password?(user, params)     user.email != params[:user][:email] ||       params[:user][:password].present?   end end 

application_controler.rb

class applicationcontroller < actioncontroller::base   protect_from_forgery with: :exception    before_filter :configure_permitted_parameters, if: :devise_controller?    def configure_permitted_parameters     devise_parameter_sanitizer.for(:account_update) |u|       u.permit(:first_name, :last_name, :username, :email, :avatar, :password, :password_confirmation)     end     devise_parameter_sanitizer.for(:sign_up) |u|       u.permit(:first_name, :last_name, :username, :email, :password, :password_confirmation)     end     devise_parameter_sanitizer.for(:sign_in) |u|       u.permit(:username, :email, :password)     end   end end 

routes.rb

projectfoo::application.routes.draw   devise_for :users, :controllers => { :registrations => "registrations",                                        :invitations => 'users/invitations' } 

note: i'm using devise_invitable gem

views/devise/registrations/edit.html.erb

<h2>edit <%= resource_name.to_s.humanize %></h2> <%= image_tag @user.avatar.url(:square) %>  <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-horizontal' }) |f| %>   <%= devise_error_messages! %>    <div class="span5">     <div class="control-group">       <%= f.label :email, :class => 'control-label' %>         <div class="controls">           <%= f.email_field :email, :autofocus => true, :class => 'text_field' %>         </div>     </div>      <div class="control-group">     <%= f.label :username, :class => 'control-label' %>       <div class="controls">        <%= f.text_field :username, :autofocus => true, :class => 'text_field' %>       </div>     </div>      <div class="control-group">       <%= f.label :first_name, :class => 'control-label' %>         <div class="controls">           <%= f.text_field :first_name, :autofocus => true, :class => 'text_field' %>         </div>     </div>      <div class="control-group">       <%= f.label :last_name, :class => 'control-label' %>         <div class="controls">           <%= f.text_field :last_name, :autofocus => true, :class => 'text_field' %>         </div>     </div>      <div class="control-group">       <%= f.label :twitter_handle, :class => 'control-label' %>       <div class="controls">         <%= f.text_field :twitter_handle, :autofocus => true, :class => 'text_field' %>       </div>     </div>      <div class="control-group">       <%= f.label :avatar, :class => 'control-label' %>         <div class="controls">           <%= f.file_field :avatar, :class => 'file_field' %>         </div>     </div>   </div>    <div class="span5">     <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>       <div>currently waiting confirmation for: <%= resource.unconfirmed_email %></div>     <% end %>      <div class="control-group">       <%= f.label :password, :class => 'control-label' %>         <div class="controls">           <%= f.password_field :password, :autocomplete => "off", :class => 'password_field' %><br><i>(leave blank if don't want change it)</i>         </div>     </div>      <div class="control-group">       <%= f.label :password_confirmation, :class => 'control-label'  %>         <div class="controls">           <%= f.password_field :password_confirmation, :class => 'password_field' %>         </div>     </div>      <div class="control-group">       <%= f.label :current_password, :class => 'control-label'  %>         <div class="controls">          <%= f.password_field :current_password, :class => 'password_field' %><p><i>(we need current password confirm changes)</i></p>         </div>     </div>     <%= f.submit "update" %>    </div> <% end %>  <div class="span11">   <hr> </div>  <div class="span11">   <h3>cancel account</h3>    <p>unhappy? <%= button_to "cancel account", registration_path(resource_name), :data => { :confirm => "are sure?" }, :method => :delete %></p>    <p><%= link_to "back", :back %></p> </div> 

you have update_with_password twice. second time should update_without_password.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -