32
loading...
This website collects cookies to deliver better user experience
models/post.rb
class Post < ApplicationRecord
has_rich_text :body
end
example from github issue
class MigratePostContentToActionText < ActiveRecord::Migration[6.0]
include ActionView::Helpers::TextHelper
def change
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
remove_column :posts, :old_body
end
end
rails g migration ConvertPostBodyToRichText
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
end
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
end
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
remove_column :posts, :old_body, :text
end
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
end
def down
add_column :posts, :old_body, :text
end
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
end
def down
add_column :posts, :old_body, :text
Post.all.each do |post|
post.update_attribute(:old_body, post.body.to_plain_text)
post.body.delete
end
end
end
20211229035004_convert_post_body_to_rich_text.rb
class ConvertPostBodyToRichText < ActiveRecord::Migration[6.1]
include ActionView::Helpers::TextHelper
def up
rename_column :posts, :body, :old_body
Post.all.each do |post|
post.update_attribute(:body, simple_format(post.old_body))
end
end
def down
add_column :posts, :old_body, :text
Post.all.each do |post|
post.update_attribute(:old_body, post.body.to_plain_text)
post.body.delete
end
rename_column :posts, :old_body, :body
end
end