Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy columns mistakenly created by Paperclip in Ruby on Rails

As the title suggests, I accidentally add some random attachment columns to my model. Say I did rails generate paperclip portfolio href

How do I remove those columns created? rails destroy paperclip portfolio href doesnt seem to work!

like image 760
donkey Avatar asked Aug 20 '14 01:08

donkey


People also ask

How do you delete a column in Rails?

remove_column :table_name, :column_name, :type Removes column, also adds column back if migration is rollbacked. Note: If you skip the data_type, the migration will remove the column successfully but if you rollback the migration it will throw an error.

What is Paperclip in Rails?

Paperclip is an easy file attachment library for Rails Applications. Attached files are saved to the file system, database or cloud and referenced in the browser by an easily understandable specification.


1 Answers

For recent version rails 4++
Just create a migration
Example:

rails g migration remove_attachment_photo_to_course
Then open the migration file

class RemoveAttachmentPhotoToCourse < ActiveRecord::Migration                                                                                                                                                                             
  def change                                                                                                                                                                                                                                   
    remove_attachment :courses, :photo                                                                                                                                                                                                   
  end                                                                                                                                                                                                                              
end

Then run, to update the table

rake db:migrate 

Where:
photo is the name of paperclip attachment you want to remove
courses is the name of table name

like image 94
abdimuna Avatar answered Sep 25 '22 12:09

abdimuna