Question

I have created few static pages with awesome high_voltage gem.

My pages are static, except a different form in each page.

Forms are supposed to grab user details and send emails (and may be save details in db)

Question:

How should I proceed with this ?

I am concerned more about rails approach,

e.g.

  1. How can I add validation without custom coding (both at client / server side)
  2. How can take help from rails helper method ?

Suppose, I would like to save those fields in db, how should I deal with that ?

In nutshell, I want to use as maximum of rails magic without manually dealing with things.

What I have tried ?

Currently, I have forms in each page. Each form posts at same controller (PagesController) with post method.

I then differentiate them, based on hidden input on respective form.

I do not have any validations for now.

Was it helpful?

Solution

I finally created a model without activerecord, following this great article.

I created a model like below.

class Message

  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :name, :email, :subject, :body

  validates :name, :email, :subject, :body, :presence => true
  validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end

end

OTHER TIPS

I have answered this post in more detail here: Render partial from static page

Here is the commit to a demo repository to make this work: https://github.com/harlow/high_voltage_demo/commit/0cdbca5b0fe898d27df22787498fc7e350e81422

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top