2

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.

Jashwant
  • 28,410
  • 16
  • 70
  • 105
  • Proceed with what? What is your goal? What isn't working? What errors are you seeing? Where is you code? – user229044 Oct 29 '13 at 17:14
  • Since, I do not have any controller, I just have few html pages. Where should I submit my form and how to deal with that on backend ? – Jashwant Oct 29 '13 at 17:18

2 Answers2

1

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
Jashwant
  • 28,410
  • 16
  • 70
  • 105
0

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

Community
  • 1
  • 1
harlow
  • 844
  • 9
  • 17