0
votes

I'm now using Devise gem in a Ruby application. It seems a password method doesn't work because in somehow, devise controller is a bit modified. When I typed /users/password/new, it goes back to a root.

I followed a tutorial but now I'm stuck at this really important method that I have to provide to the people.

The passwords_controller.rb file is located in controllers/users/password_controller.rb.

And the code is

class Users::PasswordsController < Devise::PasswordsController

  prepend_before_filter :require_no_authentication
  # Render the #edit only if coming from a reset password email link
  append_before_filter :assert_reset_token_passed, only: :edit

  # GET /resource/password/new
  def new
    self.resource = resource_class.new
  end

  # POST /resource/password

  def create
    self.resource = resource_class.send_reset_password_instructions(resource_params)
    yield resource if block_given?

    if successfully_sent?(resource)
      respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
    else
      respond_with(resource)
    end
  end

( which is a typical devise controller content )

My user.rb model goes as follow.

...
 devise :database_authenticatable,  :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:google_oauth2] #, :confirmable
...

I have view files in this directory.

views/users/passwords/create.html.erb, edit.html.erb, new.html.erb
views/users/sessions/new.html.erb
views/users/registrations/edit.html.erb, create.html.erb

Routes file goes like this

  devise_for :users, controllers: { passwords: "users/passwords", sessions: "users/sessions", registrations: "users/registrations", omniauth_callbacks: "users/omniauth_callbacks" }

Whenever I type "http://localhost:3000/users/password/new", it goes back to root.

This is my route file.

             new_user_session GET   /users/sign_in(.:format)                 users/sessions#new
             user_session POST     /users/sign_in(.:format)                 users/sessions#create
     destroy_user_session GET      /users/sign_out(.:format)                users/sessions#destroy
  user_omniauth_authorize GET|POST /users/auth/:provider(.:format)          users/omniauth_callbacks#passthru {:provider=>/google_oauth2/}
   user_omniauth_callback GET|POST /users/auth/:action/callback(.:format)   users/omniauth_callbacks#:action
            user_password POST     /users/password(.:format)                users/passwords#create
        new_user_password GET      /users/password/new(.:format)            users/passwords#new
       edit_user_password GET      /users/password/edit(.:format)           users/passwords#edit
                          PATCH    /users/password(.:format)                users/passwords#update
                          PUT      /users/password(.:format)                users/passwords#update
 cancel_user_registration GET      /users/cancel(.:format)                  users/registrations#cancel
        user_registration POST     /users(.:format)                         users/registrations#create
    new_user_registration GET      /users/sign_up(.:format)                 users/registrations#new
   edit_user_registration GET      /users/edit(.:format)                    users/registrations#edit
                          PATCH    /users(.:format)                         users/registrations#update
                          PUT      /users(.:format)                         users/registrations#update
                          DELETE   /users(.:format)                         users/registrations#destroy
                          POST|GET /:controller(/:action(/:id))(.:format)   :controller#:action
                     root GET      /                                        landings#index

The log I got when I go to localhost:3000/users/password/new goes like this.

Started GET "/users/password/new" for ::1 at 2015-10-06 04:11:58 +0900 Processing by Users::PasswordsController#new as HTML Redirected to localhost:3000 Filter chain halted as :is_login rendered or redirected Completed 302 Found in 2ms (ActiveRecord: 0.0ms) This is a log that I got right after I posted the address

If you guys have any hint, please let me know!! Best

1
Your views shouldn't have extension '.rb'. Try removing those (or replacing with .haml/.erb, depending on the contents of your files), and let us know what new problems you have.Brian
In your description you state you tried users/passwords/new but the link says users/password/new make sure that you are not accidentally visiting passwords, your route is only defined for password singular.yez
Can you post what the log shows after you go to localhost:3000/users/password/new?Brian
Are you logged in when you go to that url?Mark Swardstrom
And - what is this method? is_loginMark Swardstrom

1 Answers

0
votes

I fix it by append /users/password/edit?reset_password_token=aaaaaa maybe it is the devise bug .