How to allow devise users to edit their profil?

Posted by user1704926 on Stack Overflow See other posts from Stack Overflow or by user1704926
Published on 2012-11-13T10:53:19Z Indexed on 2012/11/13 11:00 UTC
Read the original article Hit count: 176

Filed under:

I have a namespace called "backend" which is protected by Devise. I would like now to allow users to edit their profil.

So I created a users_controller in Backend. Here's the users_controllercode :

class Backend::UsersController < ApplicationController
layout 'admin'
before_filter :authenticate_user!

    def index
        @users = Backend::User.all

         respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @users }
    end
    end

    def show
    @user = Backend::User.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @user }
    end
  end

    def edit
        @user = Backend::User.find(params[:id])
    end

    def update
    @user = Backend::User.find(params[:id])

    respond_to do |format|
      if @user.update_attributes(params[:user])
        format.html { redirect_to @user, notice: 'Article was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end
end

When I go on backend_users_path there is a list of all the users. I would like to permit to edit only his own profil. So I go on the Edit page : <%= link_to "Edit", edit_backend_user_path(backend_user.id) %> . Here's the Edit page code :

<%= simple_form_for @user do |f| %>
  <div><%= f.label :email %><br />
  <%= f.input :email, :autofocus => true %></div>

  <div><%= f.submit "Update" %></div>
<% end %>

And there is my problem : when I try to modify the email address, nothing happen. The update fails.

How can I do this ? I'm quite lost. Thanks by advance.

© Stack Overflow or respective owner

Related posts about ruby-on-rails