Created
October 13, 2015 14:35
-
-
Save dbarrionuevo/193a2a17f4918a7696f4 to your computer and use it in GitHub Desktop.
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
/ app/views/organizations/signup_modules/_organization.html.slim | |
= f.fields_for :organization, @resource.build_organization do |org| | |
.row | |
.col-md-12 | |
= org.label :name, '* Organization Name' | |
= org.text_field :name, validators: { not_empty: true }, autofocus: true |
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
/ app/views/organizations/new.html.slim | |
.col-xs-12.content | |
h1 Sign-Up Form | |
h2 Thanks for your interest in ArkansasGives. | |
p Form items indicated with * are required. | |
h2 About Your Organization | |
= form_for @resource, url: organizations_path, data: { behavior: 'organization_sign_up' }, builder: Core::ValidatableFormBuilder do |f| | |
= render 'organizations/signup_modules/organization', f: f | |
= render 'organizations/signup_modules/organization_detail', f: f | |
= render 'organizations/signup_modules/categories', f: f | |
= render 'organizations/signup_modules/counties', f: f | |
= render 'organizations/signup_modules/contact', f: f | |
= f.submit 'Submit Form', class: 'btn btn-success' |
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
# models/core/organization/sign_up.rb | |
class Core::Organization::SignUp < ActiveType::Object | |
attribute :organization | |
attribute :organization_detail | |
attribute :organization_contact | |
attribute :category_ids | |
attribute :county_ids | |
validates :organization, :organization_detail, | |
:organization_contact, presence: true | |
validates :category_ids, presence: { message: "Categories can't be blank" } | |
validates :county_ids, presence: { message: "Counties can't be blank" } | |
validate :valid_organization? | |
validate :valid_organization_detail? | |
validate :valid_organization_contact? | |
before_save :assign_categories | |
before_save :assign_counties | |
after_save :save_organization | |
def build_organization | |
@organization ||= ::Organization.new(organization) | |
end | |
def build_organization_detail | |
@organization_detail ||= build_organization.build_organization_detail( | |
organization_detail | |
) | |
end | |
def build_organization_contact | |
@organization_contact ||= build_organization.build_organization_contact( | |
organization_contact | |
) | |
end | |
private | |
def save_organization | |
build_organization.save | |
end | |
def assign_categories | |
build_organization.category_ids = category_ids | |
end | |
def assign_counties | |
build_organization.organization_county_ids = county_ids | |
end | |
def valid_organization? | |
unless build_organization.valid? | |
errors.add(:organization, build_organization.errors.full_messages) | |
end | |
end | |
def valid_organization_detail? | |
unless build_organization_detail.valid? | |
errors.add(:organization_detail, build_organization_detail.errors.full_messages) | |
end | |
end | |
def valid_organization_contact? | |
unless build_organization_contact.valid? | |
errors.add(:organization_contact, build_organization_contact.errors.full_messages) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment