1
votes

I am using devise and i am trying to allow user to modify their information without providing their information. I have followed the tutorial https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-account-without-providing-a-password.

I have this link to allow user to change their own settings

<%= link_to "Account Settings", edit_user_registration_path(current_user) %>

What I did his follow

rails g controller Registration

In the registrations controller replace the content with this

class RegistrationsController < Devise::RegistrationsController
  def update
    @user = User.find(current_user.id)
    email_changed = @user.email != params[:user][:email]
    password_changed = !params[:user][:password].empty?

    successfully_updated = if email_changed or password_changed
      @user.update_with_password(params[:user])
    else
      @user.update_without_password(params[:user])
    end

    if successfully_updated
      set_flash_message :notice, :updated
      # Sign in the user bypassing validation in case his password changed
      sign_in @user, :bypass => true
      redirect_to after_update_path_for(@user)
    else
      render "edit"
    end
  end
end

And in route.rb file i did this

devise_for :users, :controllers => { :registrations => "registrations" }

But it still bring me to the folder /views/devise/registration/edit.erb.html instead of bringing me to /views/registrations/edit.erb.html. I also restarted the server and my computer but no clue what else to do

Update: Note(customers = Users)

Started GET "/customers/edit.2" for 127.0.0.1 at 2012-12-09 20:06:03 -0500
Processing by Devise::RegistrationsController#edit as 
  [1m[35mCustomer Load (0.3ms)[0m  SELECT `customers`.* FROM `customers` WHERE `customers`.`id` = 2 LIMIT 1
  [1m[36mPage Load (0.2ms)[0m  [1mSELECT `pages`.* FROM `pages` [0m
  [1m[35mTag Load (0.2ms)[0m  SELECT `tags`.* FROM `tags` 
  Rendered devise/registrations/edit.html.erb within layouts/application (0.1ms)
  Rendered layouts/_shim.html.erb (0.0ms)
  Rendered layouts/_iewrap.html.erb (0.0ms)
  Rendered layouts/_header.html.erb (1.1ms)
  Rendered layouts/_search_tags.html.erb (0.0ms)
  Rendered layouts/_navigation.html.erb (0.8ms)
  Rendered layouts/_thirdcol.html.erb (0.0ms)
  Rendered pages/_link.html.erb (0.0ms)
  Rendered layouts/_footer.html.erb (0.4ms)
Completed 200 OK in 41ms (Views: 36.4ms | ActiveRecord: 0.7ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-12-09 20:06:04 -0500
Served asset /application.css - 304 Not Modified (5ms)


Started GET "/assets/activity_managers.css?body=1" for 127.0.0.1 at 2012-12-09 20:06:04 -0500
Served asset /activity_managers.css - 304 Not Modified (0ms)

this is the path i get to

http://localhost:3000/customers/edit.2
2

2 Answers

1
votes

You got the name and location of your file wrong.

  1. The file should be called edit.html.erb, not edit.erb.html.

  2. The file should be localed in app/views/registrations.

Also, whenever a url has .id appended at the end, it means that you are passing something to the url helper that you shouldn't be. So in this case, you can remove the current_user argument and use your link like this:

<%= link_to "Account Settings", edit_user_registration_path %>
0
votes

In config/initializers/devise.rb, uncomment this line config.scoped_views = true then restart Rails server. Also check if your edit.erb.html is in the right directory, it may be need to be in app/views/users/registrations/.

UPDATE: You need to define edit method in your RegistrationsController because without it will inherit from Devise's RegistrationsController and consequently render Devises's views. Just add these two lines to the controller and it should work.

def edit
end