Extending Database_form to send Emails via Mailer extension

I recently used Radiant to complete a project that was to build a site that was sitting on top of a Ruby on Rails application. The easiest way for them to be able to manage it without my supervision was to have it built on top of a CMS. Of course, the future plan is always to sell something online or maybe build a community for their site, but right now, a static corporate website was well enough.

Having a static site built in Rails has its pros and cons. IMHO, as a static site, you've got the super easy, straightforward utilization of caching. So its going to be superfast! The templates can easily be updated, as well as the graphics. No fancy hardcoding necessary. But still, though its fairly easy for good RoR developers such as myself, its a lot harder for the common programmer who lives and thrives in easy markups.

On the onset of an exciting idea of building a new Rails powered application, the following options automatically crossed my mind:

  • Use a social networking template application such as LovdbyLess or Community Engine.
  • Use a blogging engine such as Typo or Mephisto
  • Use a CMS such as Radiant, and something else (see, I'm a bit biased here.. I don't remember any other CMS as good as Radiant).
  • Use a blank Rails application template that has a lot of plugins built in already, like Bort.
  • Alright, be a hero and start everything from scratch (maybe you have 3months dev time, full time? err)

A few more inputs from them and I understand that they only needed a static site wherein they can change the contents at any given time, and maybe sell some stuffs online soon. And, now the new baby is born out of Radiant!

Radiant is just a gem. Its installation is very easy, and super fast. I really didn't have much trouble. But the thing is, I wanted to have more control over the code itself, since I will be tweaking the Radiant app into something that fits their needs, and my deliverables too. And so, if you end up with this decision, just unpack your radiant gem.


gem unpack radiant

Once you have the tree generated, you'll see that its a normal Rails application hiding in the gem. Now you can inspect the code, and have it tweaked according to your will. I made changes in some of the templates, stylesheets, etc, and added some extensions. One of the uses of the site would be to serve as a mail form where users can contact them via a feedback section. I checked out their Third Party extensions which was quite extensive enough. I found a couple of them that I really needed:

It was pretty sweet and less complicated. The only caveat I had to take note was that, you can't do the usual:


rake radiant:extensions:<extension>:migrate

if you don't make sure that in your


vendor/extensions

you have the extension name separated by underscores not by dashes. I had to google this up just to know what went wrong after pulling a copy of the extension repository into my vendor/extensions folder.

The next problem was really tricky. After learning about extensions, I kept looking for ways to be able to use the mailer on my database_form page. I found the clue here. Though it wasn't really what I needed. So, after randomly looking for an available solution, I quit and started to work on my own workaround. If I'm reinventing the wheel or if someone knows any other resource, please be sure to post it here. wink

If you want to try this out, do this at your own risk. It works for me, that's all I can say.. and whoops, no test for this one. smile First, make sure that you have your mailer extension set up already and working. Next, get database_form and have it set up too and already working. Once you have these two, then let's move forward.

Your database_form page should have a mailer section. Your mailer section should at least have the following example information:

1
2
3
4
5
  subject: Confirmation notification for <your site name>
  from: noreply@sweetperceptions.com
  redirect&#95;to: /contact-us/thank-you
  recipients:
    - email@email.com

In your vendor/extensions/database_form/app/models/database_form_page.rb, add this line to the method save_form in its else clause just before true:


send_static_email(form_data) unless self.parts.find_by_name('mailer').blank?

Then add the send_static_email method contents as such:

1
2
3
4
5
  def send_static_email(form_data)
    mailer_config = YAML::load(self.parts.find_by_name('mailer').content).symbolize_keys
    mail = Mail.new(self, mailer_config, form_data)
    mail.send
  end

After that, every entry to the database form will send the notification to your desired recipients. Hope this works for you guys wanting to have that feature set for Radiant.

Recommend me on Working With Rails

If you found this post of any use, then please take the time to recommend me on Working with Rails.

Leave a Reply

Hi, I've been busy you know. wink If you don't know yet, this site and my blog codes are hosted in . I recently moved to Git and found that they have support for private Git repositories. Below are details of my last git push.

Maricris S. Nonato on 14 Feb
Commit: 48fe3652ffb644af13f4a5651f9d80474b09f622

Adding new ad image for Pledgie campaign - campaign image for coderkitty fundraising
  • my mom is preventing me from doing work.. distracting me by offering fruits. sigh.. 2010-03-11
  • while creating mockups, i even find myself thinking in partials.. hmm.. too much ROR 2010-03-11
  • RT @makieduardo: "Keep me safe, O God... for in you I take refuge." (Psalm 16:1) 2010-03-11
  • @packetlog Philosophies of India? That wasn't in my list, but if you think its worth the read, then why not?! smile 2010-03-11
  • i'm on a voyage to read over 1101 books! smile 2010-03-10
  • @nightdreamer vampires? lol. i don't even like them as much as a commoner.. wink whoops! not to pull on any string there! tongue 2010-03-10
  • why is it that i find myself attracted more to classic novels?? 2010-03-10
  • @codinghorror lol. i'd love to see that happen tongue 2010-03-10
  • @gregmoreno had a look at that a long time ago. isn't it expensive though? or is it worth it? 2010-03-10
  • it took 3 yrs for Kindle to be introduced globally.. i wonder how long i have to wait for Nook sad 2010-03-09
  • Kill the zombie browser!!! 'Funeral' held for aging Web browser - CNN.com http://bit.ly/brlGYF.. 2010-03-08
  • @holtaway http://twitpic.com/17cws.. - adorable!!! 2010-03-08
  • http://twitpic.com/17cwo.. - Its hard to work when this is your setup.. 2010-03-08
  • tea + ambient music. puts my soul at ease 2010-03-08
  • 15 Quality Web-Based Applications to Create Mock-Ups and Wireframes | Spyre Studios http://bit.ly/azTHis.. 2010-03-07
  • 10 Completely Free Wireframe and Mockup Applications - Speckyboy Design Magazine http://bit.ly/9xhgFw.. 2010-03-07