Skip to content

Instantly share code, notes, and snippets.

@zerothabhishek
Created January 26, 2017 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerothabhishek/c5894bd3bb5baca9a29bdb847efb9c2a to your computer and use it in GitHub Desktop.
Save zerothabhishek/c5894bd3bb5baca9a29bdb847efb9c2a to your computer and use it in GitHub Desktop.
class FacilitiesServicesForm
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
# These are sort of like the has_many relation
attr_accessor :facilities_offerred,
:services_offerred
def initialize(params = {})
@facilities_offerred = []
@services_offerred = []
assign(params) if params.present?
end
def load(args)
load_facilities
load_services_offerred
self
end
def assign(params)
assign_facilities(params)
assign_services(params)
self
end
def save(args)
save_facilities
save_trade_services
true
end
end
## show action:
## f = FacilitiesServicesForm.new
## f.load(some_models)
## Create action:
## f = FacilitiesServicesForm.new(params)
## f.save
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment