开发者

Rails Devise Url

开发者 https://www.devze.com 2023-04-11 06:01 出处:网络
In rails devise when I set up a user, then delete him, then recreate I get a weird effect. Like this, kevin ... (delete) ... recreate kev开发者_JS百科in then the new url is kevin --2 (if I do this ag

In rails devise when I set up a user, then delete him, then recreate I get a weird effect. Like this, kevin ... (delete) ... recreate kev开发者_JS百科in then the new url is kevin --2 (if I do this again it is kevin --3. make it stop


if you create a user in a Rails application, and then delete the user, the ID in the database for that user will be not available after the user is deleted.

e.g. you start with an empty system, there are no entries in the User table...

100.times do |i|
   u = User.create(:name => "Kevin")    
   puts "User ID: #{u.id}"
   u.delete
end

what you will see is that IDs from 1..100 are used -- each new user entry (regardless if the name is the same!) will have the consecutively higher ID , e.g. the next available unused ID in the DB. And you will see that ID of course as part of the restful URL.

If you run the above code twice, you will see that it will use IDs 101..200 the second time around.

So what you are seeing is normal Rails behavior.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号