Class: Forms::Form
- Inherits:
-
Wheelhouse::Resource
- Object
- Wheelhouse::Resource
- Forms::Form
- Includes:
- Wheelhouse::Resource::Addressable, Wheelhouse::Resource::Content, Wheelhouse::Resource::Node, Wheelhouse::Resource::Renderable, Wheelhouse::Resource::Versioned
- Defined in:
- app/models/forms/form.rb
Instance Attribute Summary collapse
-
#current_submission ⇒ Object
Returns the value of attribute current_submission.
-
#success ⇒ Object
Returns the value of attribute success.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
- #deliver(submission) ⇒ Object
- #first_content_field ⇒ Object
- #handler ⇒ Object
- #recipients=(recipients) ⇒ Object
- #render(template) ⇒ Object
- #submit(params, request) ⇒ Object
- #success? ⇒ Boolean
- #to_s ⇒ Object
Instance Attribute Details
#current_submission ⇒ Object
Returns the value of attribute current_submission.
21 22 23 |
# File 'app/models/forms/form.rb', line 21 def current_submission @current_submission end |
#success ⇒ Object
Returns the value of attribute success.
21 22 23 |
# File 'app/models/forms/form.rb', line 21 def success @success end |
#view_context ⇒ Object
Returns the value of attribute view_context.
21 22 23 |
# File 'app/models/forms/form.rb', line 21 def view_context @view_context end |
Instance Method Details
#deliver(submission) ⇒ Object
44 45 46 47 48 |
# File 'app/models/forms/form.rb', line 44 def deliver(submission) Forms::Mailer.submission(self, submission).deliver unless recipients.empty? rescue # Mail delivery failed end |
#first_content_field ⇒ Object
54 55 56 |
# File 'app/models/forms/form.rb', line 54 def first_content_field @first_content_field ||= fields.flatten.find { |f| f.respond_to?(:label) } end |
#handler ⇒ Object
63 64 65 |
# File 'app/models/forms/form.rb', line 63 def handler Forms::FormHandler end |
#recipients=(recipients) ⇒ Object
58 59 60 61 |
# File 'app/models/forms/form.rb', line 58 def recipients=(recipients) recipients = recipients.split(/,/) if recipients.is_a?(String) write_attribute(:recipients, recipients.map(&:strip)) end |
#render(template) ⇒ Object
27 28 29 |
# File 'app/models/forms/form.rb', line 27 def render(template) Forms::FormRenderer.new(self, current_submission, template).render end |
#submit(params, request) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/forms/form.rb', line 31 def submit(params, request) submission = submissions.build(:params => params, :ip_address => request.remote_ip) Forms::Plugin.config.wheelhouse.forms.spam_filter.check(submission) if submission.save deliver(submission) unless submission.spam? self.success = true else self.current_submission = submission self.success = false end end |
#success? ⇒ Boolean
50 51 52 |
# File 'app/models/forms/form.rb', line 50 def success? @success end |
#to_s ⇒ Object
23 24 25 |
# File 'app/models/forms/form.rb', line 23 def to_s render(view_context) end |