scinote-web/app/serializers/table_serializer.rb

27 lines
468 B
Ruby
Raw Normal View History

2022-05-06 17:59:22 +08:00
# frozen_string_literal: true
class TableSerializer < ActiveModel::Serializer
include Rails.application.routes.url_helpers
attributes :name, :contents, :urls, :icon
2022-05-06 17:59:22 +08:00
def contents
object.contents_utf_8
end
def icon
'fa-table'
end
2022-05-06 17:59:22 +08:00
def urls
return if object.destroyed?
object.reload unless object.step
{
delete_url: step_table_path(object.step, object),
update_url: step_table_path(object.step, object)
}
end
end