开发者

db:seed - How to change a value on production?

开发者 https://www.devze.com 2023-01-26 04:01 出处:网络
I have the following db:seed which is live on heroku: [\"Admin\", \"Member\"].each do |role_name| Role.find_or_create_by_name(role_name)

I have the following db:seed which is live on heroku:

["Admin", "Member"].each do |role_name|
  Role.find_or_create_by_name(role_name)
end

Admin is ID=1 and Member is ID = 2, which is important to the entire ap开发者_开发技巧p.

I want to change Member to Teammember,

how do I do that? if I delete the old records and reseed then the ID's will be off?

Suggestions?


Just do:

member = Role.find_by_name("Member")
member.name = "Teammember"
member.save!

PS: don't rely on ID in your code ( use Role.find_by_name )

0

精彩评论

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