-
-
Save contentfree/96485d4d3c3dab099f0247a269721418 to your computer and use it in GitHub Desktop.
An attempt at Reform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuickCampaignMessageForm < Reform::Form | |
include Composition | |
model :campaign_message | |
properties :campaign_id, :name, :subject, validates: {presence: true}, on: :campaign_message | |
property :file, on: :asset | |
property :text, on: :text_asset | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"campaign_message" => { | |
"campaign_id" => "1", | |
"name" => "Text club", | |
"subject" => "The message's subject", | |
"file" => an_uploaded_file, | |
"text" => "Thanks for joining the text club!" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simplified... | |
class CampaignMessage < ActiveRecord::Base | |
has_many :source_assets | |
end | |
class SourceAsset < ActiveRecord::Base | |
has_many :payload_assets | |
end | |
class PayloadAsset < ActiveRecord::Base | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class QuickCampaignMessagesController < ApplicationController | |
def new | |
@form = get_form | |
end | |
def create | |
@form = get_form | |
if @form.validate(params[:campaign_message]) | |
@form.save | |
# ... redirect and return ... | |
end | |
@form.prepopulate! # Maybe? | |
render :new | |
end | |
private | |
def get_form | |
# This is probably not the Right Way, and where the problems begin. Do | |
# I need an intermediate object here? | |
QuickCampaignMessageForm.new(campaign_message: CampaignMessage.new(campaign_id: params[:campaign_id]), | |
asset: SourceAsset.new, | |
text_asset: PayloadAsset.new) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment