Contact / Feedback Form Plugin for Mephisto
Introduction
If you use Mephisto, a content management / blogging system written in Rails, you may well be interested in using this new plug-in. It provides a form that lets visitors to your site leave their contact details and send you messages or feedback via email.
UPDATE
Please check out information about using the contact form plugin with Mephisto Drax 0.8.
License
This plug-in was developed for the new ThoughtWorks Studios site. As I wrote it at and for work, it is copyright ThoughtWorks, 2007. However, ThoughtWorks, being generous souls, is happy for me to open source it under the Apache 2.0 licence, which pretty much means you have free reign to use it as you want.
Requirements
- Mephisto Edge (the latest stable 0.7.3 release does not have support for Mephisto plugins)
- Rails Edge (required by Mephisto edge)
- ActionMailer (comes with Rails) correctly configured with SMTP server etc, so that emails can be delivered. See “Configuration” section here for more details.
Installation
ruby script/plugin install http://mephisto-contact-form-plugin.googlecode.com/svn/plugins/mephisto_contact_form
or in your vendor/plugins directory for Mephisto:
svn checkout http://mephisto-contact-form-plugin.googlecode.com/svn/plugins/mephisto_contact_form mephisto_contact_form
Make sure you restart your web server at this point so that the plugin is loaded.
Setup
1. Create a new template called ‘contact_us.liquid’ though the admin web interface (under the ‘Design’ tab).
Paste in the following code:
<H1>Contact Us</H1>
{% contactform %}
<p>{{ form.name }}<label for="author"><small>Your name</small></label></p>
<p>{{ form.email }}<label for="email"><small>Email address</small></label></p>
<p>{{ form.phone}}<label for="phone"><small>Phone number (optional)</small></label></p>
<p>{{ form.subject}}<label for="subject"><small>Subject</small></label></p>
<p>{{ form.body }}</p>
<p>{{ form.submit }}</p>
{% endcontactform %}
Feel free to modify labels, layout etc.
2. Edit
{MEPHISTO_ROOT}/vendor/plugins/mephisto_contact_form/lib/contact_notifier.rb
and put in the email address you want contact form submissions to go to.
3. Link to “/contact_form” from your site.
Any issues / questions / suggestions?
Best to post comments on this blog.
Technical Info
The contact form plugin is actually a combination of a rails plugin, a liquid block plugin and a Mephisto plugin. See this post about developing Mephisto plugins for more information.

Hi James,
For #3 “Link to “/contact_form” from your site.”. How do you exactly go about doing that.
Does that mean to add a new section from the admin panel and use the contact_us.liquid as the page template.
Let me know if you could provide more specific instructions for this.
Thanks.
No need to add a new section in the admin panel. Once the plug-in is installed, it adds a route to /contact_form to Mephisto. Say you want to link to the contact form from a page, you would add a link like this:
<a href=”/contact_form”>Contact Us</a>
Hello james
thanks for your work on the contact form. it was exactly what I was looking for. Had to install a new trunk version of Mephisto to make it work - but in the final…
Cheers
Michael
P.S. Any idea how to use iframes in Rails? Is there a plugin somewhere out there in the Rails world? Or another solution?
Hi Michael,
Thanks for your comment. Depending on your requirements, a better solution may be to use ajax and divs. See more info here:
http://www.onlamp.com/pub/a/onlamp/2005/06/09/rails_ajax.html
Hi James,
I’m using 0.7.3
is there a solution of some sort to actually make it work in v0.7.3?
what could I do as an alternitive.?
Thanks in advance
Brian
Hi Brian,
I haven’t tried it, and there may be more gotchas, but if you install the plug-in and then add the routes manually to Mephisto’s routes.rb that are in here:
http://mephisto-contact-form-plugin.googlecode.com/svn/plugins/mephisto_contact_form/lib/plugin.rb
it may well work
Also, if you set up a test database, you should be able to run the unit tests and see if anything else is lacking/broken.
Please post to tell me how it goes!
Cheers,
James
Hello! Thanks for your plugin. It work good. How can I add a layout for this page or if it’s not possible show the title of the page (ex: My Site | Contact).
Thanks in advance.
Hi James - great plugin!
I added a very minor modification to allow the user to update the destination email address in the plugin configuration.
The changes are listed here: http://joshhuckabee.com/mephisto_contact_form_modification
Thanks again!
Thanks for a great contribution!
Now my next question is how to get plugins to load on a shared hosting situation at RailsPlayground, where “restarting my Rails app” is not an option. Hmmm….
Hi Phillip,
Assuming your hosting is apache fast cgi, you can kill any processes running under your user called dispatch.fcgi. That should be pretty much the same as a server restart.
Cheers,
James
Thanks, James.
Unfortunately, I’m still having a horrific time getting it going under stable 0.7 of Mephisto (rev. 2852, last changed 2828) and Rails 1.2.2 on my shared Linux hosting. RailsPlayground reports the following when they run via Webrick:
=> Booting WEBrick…
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:266:in `load_missing_constant’: uninitialized constant Mephisto::Plugin (NameError)
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in `const_missing’
from ./script/../config/../vendor/plugins/mephisto_contact_form/lib/plugin.rb:3
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:342:in `new_constants_in’
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:495:in `require’
from script/../config/../vendor/plugins/mephisto_contact_form/init.rb:12:in `load_plugin’
… 21 levels…
from /usr/local/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/commands/server.rb:39
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from script/server:3
As it happens, I get exactly the same problem on my local Win XP installation, which at least makes troubleshooting easy.
I seem to recall seeing this problem with another app, and it may have been the results of some change in the plugin system. I feel like I’m missing some step, as though my versions are mismatched or something. Any ideas?
Thanks,
Philip
Sorry, i can’t read. Is Mephisto Edge a reliable platform for one’s professional Web site? It certainly sounds like I’d be better off with a stable version, but then I’m going to have to attempt your hacking suggestions in the comment to Brian above.
Should I ask Rick for a development roadmap so I can assess when I can get a stable version of Mephisto that supports this plugin? Or is such a roadmap published somewhere?
Hi Phillip,
The last Mephisto release was almost a year ago.. I don’t know when the next one is due - probably best to ask Rick as you suggest, and also get his opinion on edge stability.
James
Hi James and thanks for your wonderful plugin,I was using it flawlessly on my mephisto trunk, now i setup a new mephisto install on mediatemple, do no tknwo why, but actually when i am trying to send emails after setting up all the things as specified i got an error page?????mmmm i checked my production.log and i’ve found a weird message (i am pasting here the main line from my log saving your time from reading all the rest, but i guess this is the main error)
NoMethodError (undefined method `com’ for nil:NilClass):
/vendor/plugins/mephisto_contact_form/lib/contact_notifier.rb:7:in `contact_notification’
it seems something is wrong when i setup my recipients into contact notifier.
Do not know what i am doing wrong actually i specified “somename@someemailaddress.com”
it seems that it doesn’t like the “.com” part of the thing:)
Any help is highly appreciated and thanks again for your wonderful contribution
Hey James,
Great plugin. I’ve got everything working except I’m not receiving the email. My logs show the email that is sent and I’ve tried configuring it to use both smtp and sendmail.
Have you got any tips for debugging ActionMailer and its configuration?
Cheers
Dylan
Hey everyone. I was wondering if anyone knows a way to detect in my layout when I am on the contact form? I would like to know this in order to render a tab in my css as style=’selected’.
Is there anyway to know this??
ex:
{% if site.current_section.name == “Contact” %} or something like this?
[…] I was writing a contact form plugin for Mephisto, I had a lot of trouble finding documentation and ended up reading lots of code and […]
Not sure why, but when I put this into to Mephisto edge on rails 1.99.1 it would return a 404 error on looking at localhost/contact_form.
I dug around the console, it was showing up on the custom_routes as well as in the $LOAD_PATH… just wasn’t showing up in ActionController::Routing::Routes.routes
Handling was to put the following into the config/routes.rb file to hard code the routes in and now it works fine.
ActionController::Routing::Routes.draw do |map|
Mephisto::Routing.connect_with map do
map.contact "/contact_form",
{ :action=>"contact_form",
:controller=>"contact_form" }
map.contact "/contact_submit",
{ :conditions=>{:method=>:post},
:action=>"contact_submit",
:controller=>"contact_form"}
end
end
Hope that helps someone else.
Mikel
Thanks Mikel for finding this and sending me a patch. I’ve applied it tonight to the contact form repository.
Something seems to have changed in either Edge Rails or Edge Mephisto that breaks the Mephisto plug-in API’s add_route method. The problem seems to be that Mephisto route configuration (lib/mephisto/routing.rb) is now happening before plug-ins are loaded. Previously, plug-ins were loaded before Mehisto route configuration was done. I’ll investigate further when I get a chance. Keen to hear ideas on a fix for add_route
Cheers,
James
I’m on mephisto revision 3074 with rails 2.0.2 and the add_routes methods seem to be working. In fact, I had to use them instead of the routing patch. Just an FYI.
Thanks for the plugin!
the email bodies are showing up in my rails application logs, causing a large amount of wasted space. Anybody know how to prevent this?
Suggest increasing your logging level filtering in production. See:
http://maintainable.com/articles/rails_logging_tips#log-levels
James
Mark, that’s good news and thanks for dropping me a line. I’ve updated the code back to using add_route.
James
Man, I wish I could use this but I’m a rails noob and can’t figure out what is wrong. When I install it I get an application error. Nothing is written in my logs when this happens either. Am I doing something wrong?
Hey Nic,
Are you running with apache fcgi? Maybe this post might help:
http://jamescrisp.org/2006/08/19/ruby-on-rails-hosting-setup-and-migration/
Cheers,
James
Hey James,
Ths for the share, nice to see that the Plugin is easily extensible.
When installing i didn’t see the version required while my mephisto is 0.7.2. Now i got a problem the same with Philip.
How could i unistall the plugin now?
THANKS.
Roche Foo
Hi Roche,
To uninstall any rails plug-in you should just be able to delete the directory:
[RAILS ROOT]/vendor/plugins/[PLUGIN NAME]
James
Ths a billion, it works.
[…] Drax (version 0.8) introduces breaking changes for plugins. I’ve just finished updating the contact / feedback form plugin. It’s now working fine and tests […]