Software dev, tech, mind hacks and the occasional personal bit

Category: Ruby / Rails Page 4 of 7

Contact Form For Mephisto updated for Drax 0.8

Mephisto 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 passing.

Installation instructions are the same as before except that the ‘contact_notifier’ has moved from the ‘lib’ directory to the ‘app’ directory. It still needs to be updated to include your destination email address for contact mails.

If you’re a Mephisto plug-in developer, you might be interested in checking out my post on migrating Mephisto plugins to Drax. It’s based on my experiences with the contact_form.

Migrating Mephisto Plugins to Drax 0.8

There have been some major changes to Mephisto in the latest release (0.8 Drax) that break existing plugins. If you’re interested in migrating your existing plugin(s) over to Drax, read on.

Repository Move
First thing to note is that the Mephisto code base has moved from SVN to github.

Plugin Architecture Changes
There is no longer a base class for Mephisto plugins. Instead, you create Mephisto plugins using Rails Engines. If you’re migrating a pre-Drax plugin to Drax and Rails engines, you’ll most likely need to:

  • Remove your plugin file – there’s no base class for it any more so you’ll get errors like: ‘superclass must be a Class (Module given) (TypeError)’
  • Move your routes into a ‘routes.rb’ file in your plugin root directory.
  • In your plugin root directory, create an ‘app’ directory, with ‘views’, ‘models’ and ‘controllers’ sub-directories. Move your code files into the appropriate folders in the ‘app’ directory. These will be auto-loaded.
  • Remove various lines in your init.rb which manually add your plugin file directories to the load paths, if you have these.
  • If you inherit from the ApplicationController, add ‘unloadable‘ to your controller class. This will fix errors in development mode like ‘A copy of ApplicationController has been removed from the module tree but is still active!’
  • An example
    You can have a look at my contact_form plugin code. Revision 18 is before Drax and engines and uses the old approach. Revisions 19 and later are using Rails engines and will work with Drax.

    UPDATE: Latest code at GitHub
    http://github.com/jcrisp/mephisto_contact_form/tree/master

RiskAssess – Risk Assessments for Schools

I’ve been developing RiskAssess, an online risk assessment system for schools. RiskAssess helps teachers and lab assistants to quickly and easily produce risk assessments for laboratory experiments which meet Australian standards. RiskAssess should help decrease the number of accidents in school laboratories, and also help schools meet legal requirements.

I’m pleased to say that the site is now well and truly launched and we have schools doing risk assessments every day using RiskAssess. There’s still much to do and many new features to add, but so far we’ve had very positive feedback from the schools using the system.

On the technical side, RiskAssess is a Ruby on Rails site.

Loan Calulator: Monthly repayment and interest breakdown

Wondering if your loan repayment calculations have been performed correctly this month, taking into account interest rate rises and extra repayments? You might be interested in giving my monthly loan calculator a go.

As my home loan provider doesn’t show balances online, and only sends statements every 6 months, I like to ring up every month or two to make sure things are on track. I used to calculate interest, new balances etc in a spreadsheet / calculator but spent an afternoon writing a little Rails app to calculate it for me. Hopefully my little monthly loan calculator is of some use to you too.

Sydney BarCamp 3 this Weekend!

BarCamp Sydney is two days long this year, and will span the whole of the coming weekend (5-6 April). I’ll be there on Saturday. It’s usually quite a fun event, lots of good sessions and you’re quite free to move around and find something that interests you. Part of the BarCamp manifesto is that you should also contribute as well as listen – I’ll probably give a JRuby talk and demo.

Hope to see you at BarCamp!

“JRuby: Enterprise 2.0” Slides

Here’s the slides from “JRuby: Enterprise 2.0″ from our recent talks at Sun Tech Day and the ACS Web Technologies SIG.

“JRuby: Enterprise 2.0” Presentations

Josh Price and I will be co-presenting at the Melbourne Sun Tech Day and the Sydney ACS Web Technologies SIG. Here’s the low down:

JRuby: Enterprise 2.0
There’s a lot of buzz around JRuby in both the Java and Ruby communities, for good reason. This talk will give you a whirlwind introduction to JRuby. We’ll show you why JRuby is regarded as such a powerful and dynamic development platform. We’ll also suggest where to use JRuby in product development and the enterprise and how to leverage your existing Java investments.
There will be sample applications, live demos and not many slides.

Sun Tech Day Melbourne
4 March 2008, 2:30pm
More info on Sun site…

ACS Web Technologies SIG Sydney
5 March 2008, 6:15pm
More info on ACS site…

Hope to see you there!

Practical JRuby on Rails (Web 2.0 Projects) by Ola Bini

The fine folk at Apress sent me a copy of Ola Bini‘s new book to review. The full title is “Practical JRuby on Rails Web 2.0 Projects – Bringing Ruby On Rails to the Java Platform”. Overall, it was a good read, and extremely valuable to anyone who is developing in JRuby. JRuby information and documentation is scarce and most of the time, a Google trawl does not give you good results on a JRuby related query. Ola’s is the first, and currently the only JRuby book available, and in my experience, the most valuable resource available to give you an all-round picture of JRuby capabilities and usage.

Audience
Despite comments on the cover, I would suggest that this book is not ideal for people new to Ruby / Rails. Ola jumps in the deep end quite quickly, and being a talented Ruby programmer, makes use of lots of shorthand, procs, code blocks etc which would likely be hard to follow for someone new to Ruby. Although there is a section at the back called “Ruby for Java programmers”, I think this would not be sufficient for somebody new to Ruby to understand all the code examples.

To get the most value out of the book, it would be good to have at least a basic understanding of Ruby and Rails (eg, having read Agile Web Development with Rails or messed around with Ruby/Rails a bit) and a basic understanding of Java syntax, deployment and Java EE.

What’s Covered?
The book is project based, so as to give context and useful examples of JRuby functionality. There are 4 projects:

  • The Store (Shoplet) – a standard Rails app running under JRuby using Active Record JDBC.
  • Content management system – general Java integration and using Java libraries for content rendering.
  • Administration System – using EJBs, JMX and discussion of JRuby deployment options.
  • Library System – JRuby as the “glue that never sets”. Using Java Web service frameworks and JMS from JRuby.

The Good

  • Teaches you how to do all those tricky bits which are half-Java and half-Ruby and can’t be easily found online, such as converting between Ruby and Java types, including JAR files, implementing Java interfaces, etc
  • Clever and concise Ruby code – I picked up some Ruby tricks reading Ola’s code.
  • Complex code snippets are generally well explained in text.
  • Useful tips on when to use Java libraries and when to use Ruby ones.
  • Generally good and interesting example projects which justified the use of JRuby and the techniques shown in the book.
  • Helpful discussion of JDBC and database connectivity options for JRuby.
  • Nice overview of the many JRuby deployment options.
  • Helpful “sidebars” about Java Enterprise Edition technologies.
  • Covers the strong areas of JRuby well – web applications and system integration.
  • Appendices provide useful reference information.
  • Nice section at the end on how you can get involved in JRuby.

The Less Good

  • Example views often contain table layouts, inline styles and other layout information that would be better done in separate CSS files.
  • Variable names in code could be more descriptive. This would make example code easier to follow.
  • Occasional odd spelling like “sur_name” and use of deprecated Rails features, such as “start_form_tag” (to be fair though, Rails API does change very quickly).
  • The title suggests that the book is about Web 2.0. There is a little token AJAX, and I suppose a content management system is a bit Web 2.0, but overall, buy the book if you want to know about JRuby, not Web 2.0.
  • Although REST is only mentioned briefly in a little sidebar, and not a focus of the book, I found the description of REST and CRUD a bit misleading, especially when considering PUT vs POST.
  • The discussion of JRuby deployment provides a good overview, but more in depth discussion of major options (eg, GoldSpike), and production configurations would be great.

Conclusion
As the best and only JRuby reference, I’d highly recommend you buy a copy if you are working in, or planning to work in JRuby. The book will help you to write JRuby applications which make good use of Ruby, Rails, Java libraries and Java Enterprise Edition features.

Automating MySQL Database Backups

Great, so you’ve got your web application up and running on some server somewhere, and thousands of users are hard at work entering their valuable data into your application, and thence to a MySQL database. Now people depend on your system to keep their data safe. What are you going to do about it?

The approach I’ve taken is to run a backup script on a cron job, which dumps data from the database a few times a daily, compresses it, and emails it off to my GMail account. All those GMail gigabytes have got to be good for something, right :-)?

I started writing a simple backup shell script using mysqldump, gzip and sendmail, but ran into problems on RailsPlayground as sendmail is not supported there. RailsPlayground suggested this perl script for mysql backup (mirrored on my server). The script does pretty much what I was looking for, and also supports skipping tables (useful for ignoring things like session tables, which, for my app, are not really worth backing up).

A little more investigation revealed that the script wouldn’t work out of the box, as RailsPlayground requires SMTP auth. The backup script is not hard to enhance to support SMTP auth. It can be done as follows:

In the configuration section of the file (around line 203), add 2 new variables:

$smtp_user           = "my username"
$smtp_password       = "my password"

Around line 1200, add in the AuthUser and AuthPass:

MIME::Lite->send("$send_method", "$mailprog_or_smtp_host", Timeout=>60,
            AuthUser=>$smtp_user, AuthPass=>$smtp_password);

As an aside, this script can also do backups via FTP.

Restore of mysql dump files is pretty easy. You just use the standard client:

mysql -uMyUser -p MyDatabaseName < SqlDumpFile.sql

Hosting at Rails Playground, a review

I’ve been meaning to write about Rails Playground for a while. I currently use their level 2 developer hosting and I’ve been very happy with it. I host several domains and subdomains on my account. I run several rails apps (including my online wedding registry site, this blog (WordPress) and a wiki (moin) on it.

You get shell access, sFTP and cPanel, MySQL, PostgreSQL and also unlimited subversion repositories. Another neat feature is that you get 2 mongrel instances included. You need to ask Rails Playground staff to set these up for you, but they are quite prompt and friendly. I did have some problems with Mongrel instances dying, but the Rails Playground staff added a cron job to restart them, and this has solved the issue. At currently $12/month (or $9/month if you pay for a year), it is quite economical hosting.

I’d highly recommend Rails Playground if you’re a rails developer looking for hosting (with fcgi and mongrels) and subversion, and you don’t want/need the flexibility/hassle/higher price of a virtual private server.

Page 4 of 7

Powered by WordPress & Theme by Anders Norén