mardi 14 février 2017

Soft delete in rails using devise gem

Default file within registration/edit.html.erb helps us to change password as well delete current user. But i am trying to soft delete other user except current user modifying registration.erb file myself. But problem is that i could not pass proper value to satisfy condition for soft deleting user.

<%= link_to "Delete Account", registration_path(resource_name), data: {confirm: "Are you sure to delete your account?\n If you click yes your account #{current_user.email} will be deleted permanently. "}, method: :delete, :class=> "btn btn-danger" %>

It is original code to redirect towards delete, where resource_name holds id of current user i guess. So, i am welling to use same path but id of different user except current user. So can any one help me.

<table class="table table-hover">
          <thead>
          <tr class="bg-primary">
            <th>S.N.</th>
            <th>Name</th>
            <th>Email</th>
            <th>Created at</th>
            <th>Action</th>
          </tr>
          </thead>
          <% @users.each_with_index do |u, i| %>
              <tbody>
              <tr>
                <td><%= (@page.to_i - 1) * @perpage+ i+1 %></td>
                <td>
                  <% if u.first_name.present? %>
                      <%= u.first_name.slice(0, 1).capitalize + u.first_name.slice(1..-1) %>
                  <% end %>
                  <% if u.middle_name.present? %>
                      <%= u.middle_name.slice(0, 1).capitalize + u.middle_name.slice(1..-1) %>
                  <% end %>
                  <% if u.last_name.present? %>
                      <%= u.last_name.slice(0, 1).capitalize + u.last_name.slice(1..-1) %>
                  <% end %>
                </td>
                <td>
                  <%= u.email %>
                </td>
                <td>
                  <%= u.created_at %>
                </td>
                <td>
                  <a data-confirm="Are you sure to delete" rel="nofollow" data-method="delete" href="<%= user_registration_path(u) %>">
                    <span class="fa-delete">
                      <i class="fa fa-trash fa-trash-color fa-th-large fa-2x"></i>
                    </span>
                  </a>
                </td>
              </tr>
              </tbody>
          <% end %>
        </table>

This is my index page which loads all users within database. And delete button helps to delete user.

Aucun commentaire:

Enregistrer un commentaire