Reputation: 2539
I was attempting to add a tagging model to my rails blog. But I accidentally generated a "Tags.rb" model as opposed to "Tag.rb", after reading the guide I realized that making "tag" plural was a mistake when it comes to model. I rolled back the migration using
rake db:rollback
and then
rails destroy model Tags.rb
and this was what i got back
invoke active_record
remove /home/migration/templates/create_table_migration.rb
remove app/models/tags.rb.rb
invoke test_unit
remove test/models/tags.rb_test.rb
remove test/fixtures/tags.rbs.yml
When I come back to the model folder though its still there. Please help :)
Upvotes: 5
Views: 18309
Reputation: 10079
First off, when generating a Rails model using rails generate model
, don't add .rb
to the end of the model name. Rails automatically does that so if you add .rb
yourself then you end up with a model named Tag.rb.rb
, which is invalid.
You're running the remove generator with "Tags.rb
". Did you generate the model originally using rails generate model Tags.rb
? If you did, then running rails destroy model Tags.rb
will hopefully remove all the files, but since the model name is invalid, it might not work as expected (your use case is outside the intended use case of the generator). If you originally generated the model using rails generate model Tags
, then running rails destroy model Tags
should work.
If you originally invoked rails generate model Tags.rb
, and running the remove command isn't working (which again, in understandable given that Tags.rb
is an invalid name--would have been nice if the generator had originally prohibited you from generating a Tags.rb.rb
file, but you can't have everything):
rails generate model Tag
.Upvotes: 0
Reputation: 161
try this
bundle exec rake db:rollback
and then delete your model as
rails destroy model <model_name>
now totaly deleted.
Upvotes: 1
Reputation: 2786
You can delete the migration files in migrate folder and model in your model folder and then you can again create new one which you wants.
you have to run that commands
rails g model tag
Then migrate database
rake db:migrate
Upvotes: 0
Reputation: 4831
Try using tags plural without the additional .rb, like
rails destroy model Tags
Hope this helps
Upvotes: 1