Class: AirtableSync::CreateRecordJob
- Inherits:
-
ApplicationJob
- Object
- ApplicationJob
- AirtableSync::CreateRecordJob
- Defined in:
- app/jobs/airtable_sync/create_record_job.rb
Instance Method Summary collapse
-
#perform(model_name, id, table_name = model_name.underscore.pluralize.humanize) ⇒ Object
AirTable table name should be in plural form.
Instance Method Details
#perform(model_name, id, table_name = model_name.underscore.pluralize.humanize) ⇒ Object
AirTable table name should be in plural form. ‘JobListing’.underscore.pluralize.humanize => “Job listings” ‘job_listing’.underscore.pluralize.humanize => “Job listings” We can sync Rails model that has different class name than its AirTable table name model_name => Rails model that has airtable_id column table_name => AirTable table name model_name = ‘Article’; id = article.id, table_name = ‘Posts’
12 13 14 15 16 17 18 19 |
# File 'app/jobs/airtable_sync/create_record_job.rb', line 12 def perform(model_name, id, table_name = model_name.underscore.pluralize.humanize) model_class = model_name.underscore.classify.constantize record = model_class.find_by(id:) return if record.blank? return if record.airtable_base_id.blank? AirtableSync::Api.new(record.airtable_base_id).create_record(record, table_name) end |