Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5930891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:37:01+00:00 2026-05-22T14:37:01+00:00

I’m trying to pull the change password fields into a separate form, but get

  • 0

I’m trying to pull the change password fields into a separate form, but get an error with method devise_error_message!.

If I remove the method updating workings fine, however, if a validation fails it redirects to the registrations/edit.html.erb and gives the error messages. How would I get it to redirect back to the registrations/change_password.html.erb view and give the devise_error_messages! ?

All my code :
http://pastie.org/1907545

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:37:03+00:00Added an answer on May 22, 2026 at 2:37 pm

    There’s a few things that I think need to be resolved.

    1) Initialize the resource in the change_password action

    The call to devise_error_messages! fails because you aren’t initializing the resource (your User model instance) in the RegistrationsController#change_password action. One way to do this is to make sure that the authenticate_scope! before filter, which is implemented in Devise::RegistrationsController, gets called on the change_password action. Try something like this in your RegistrationsController.

    class RegistrationsController < Devise::RegistrationsController
        prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy, :change_password]
    
        def create
          ...
        end
    end
    

    If that doesn’t work, you might want to simply call authenticate_scope! at the beginning of your change_password action.

    2) Redirect to change_password.html.erb in case of a failure

    Basically both of the Devise::RegistrationsController#edit action and your RegistrationsController#change_password action submit a form to the Devise::RegistrationsController#update action. What you want to do is make sure that when an update fails, if the form submission is coming from the Devise::RegistrationsController#edit action then you render the registrations/edit.html.erb view and similarly if the form submission is coming from the RegistrationsController#change_password action then you render registrations/change_password.html.erb view.

    There are various ways to do this including relying on the flash hash to set a key in the RegistrationsController#change_password action (e.g. flash[:change_password] = true) and then check for the presence of this key if an error occurs during an update. Another approach would be to use a hidden field in your change_password form then similarly, if an error occurs during an update, check for the presence of this hidden field in the params hash. Something like this.

    <h2>Edit <%= resource_name.to_s.humanize %></h2>
    
    <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name),
                           :html => { :method => :put }) do |f| %>  
    
      <%= devise_error_messages! %>
    
      <%= hidden_field_tag :change_password, true %>
    

    Either way you will need to override the Devise::RegistrationsController#udpate action. Something like this:

    class RegistrationsController < Devise::RegistrationsController
        prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy, :change_password]
    
        def update
          if resource.update_with_password(params[resource_name])
            set_flash_message :notice, :updated if is_navigational_format?
            sign_in resource_name, resource, :bypass => true
            respond_with resource, :location => after_update_path_for(resource)
          else
            clean_up_passwords(resource)
            respond_with_navigational(resource) do
              if params[:change_password] # or flash[:change_password]
                render_with_scope :change_password
              else
                render_with_scope :edit
              end
            end
          end
        end
    end
    

    Give this a try but I think that should put you back on track.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
Seemingly simple, but I cannot find anything relevant on the web. What is the
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.