I am following the Rails Tutorial by Michael Hartl
Explanation: Currently a hundred user's in the database. I create 50 accounts more, they get user id's 101 - 150. Then the admin destroys them. When I then create yet another account, it should get user id 101 because users 101 -150 are no longer there. But it gets 151, so my user id's jump from 100 to 151 with nothing inbetween.
What causes this? There is something wrong then with destroying the accounts? below the files and console output:
The view:
(app/views/_user.html.erb)
<li>
<%= gravatar_for user, size: 50 %>
<%= link_to user.name, user %>
<% if current_user.admin? && !current_user?(user) %>
| <%= link_to "delete", user, method: :delete,
data: { confirm: "You sure?" } %>
<% end %>
</li>
The controller:
def destroy
User.find(params[:id]).destroy
flash[:success] = "User deleted"
redirect_to users_url
end
The console output when deleting user:
Started DELETE "/users/102" for $IP at 2016-03-30 12:11:52 +0000
Processing by UsersController#destroy as HTML
Parameters: {"authenticity_token"=>"Kj+2TnvVk8jVrZi1leVeQRAjJbZsKqXAhA1cjK/WNDa4TieY54NdD6OCATNANFR0lh1trhi+ZzvMLhnirZnw+g==", "id"=>"102"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 102]]
(0.1ms) begin transaction
SQL (0.3ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 102]]
(10.7ms) commit transaction
Aucun commentaire:
Enregistrer un commentaire