Markaby and Rails — 2.1.x woes
October 17th, 2008
I really like Markaby for HTML templates. I think it’s especially good if Ruby programmers are creating and updating the views. If you have to get a designer involved (i.e. non Rubyist) maybe ERB or Haml would be better, but, otherwise it’s great, because everything is Ruby.
So, I started out trying to get Markaby working with Rails 2.1.0. With some hours of confusion as to why it didn’t work and digging into Rails and Markaby code, I came up with the following two hacks which patch up Markaby to work with changes in the Rails rendering code.
In vendor/plugins/markaby/init.rb, change
ActionView::Base::register_template_handler 'mab', Markaby::Rails::ActionViewTemplateHandler
to
ActionView::Template::register_template_handler 'mab', Markaby::Rails::ActionViewTemplateHandler
Create config/initializers/markaby_fixup.rb:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# see http://onemanswalk.com/work/2007/12/13/using-markaby-w-rails-2-0-1/ ActionView::Base class ActionView::Base def string_path(string) string end end Markaby::Rails::ActionViewTemplateHandler class Markaby::Rails::ActionViewTemplateHandler def compilable?; false; end def render(template) assigns = @action_view.instance_vars.to_h.merge(template.locals) builder = Markaby::Rails::Builder.new(assigns, @action_view) eval_args = [template.source, template.filename].compact builder.capture { instance_eval(*eval_args) } end end |
So this was working fine until I updated to Rails 2.1.1, at which time I got several errors like the following:
undefined method `/people/1320/edit_path' for #<ActionView::Base:0x3d0a090>
On line #26 of people/show.html.mab
23: text h(@person.maiden_name)
24: end
25:
26: link_to 'Edit', edit_person_path(@person)
27: link_to 'Back', people_path
vendor/plugins/markaby/lib/markaby/builder.rb:166:in `send'
config/initializers/markaby_fixup.rb:26:in `method_missing'
app/views/addresses/new.html.mab:30:in `render'
vendor/plugins/markaby/lib/markaby/builder.rb:105:in `instance_eval'
vendor/plugins/markaby/lib/markaby/builder.rb:105:in `capture'
config/initializers/markaby_fixup.rb:17:in `render'
spec/views/addresses/new.html.mab_spec.rb:18
I’ll keep digging to figure out how to fix my fix so I can continue to use Markaby, but really what I’m wondering is — am I the only one trying to us Markaby with recent versions of Rails? I found a relevant bug report or two, but no apparent action to fix them. I’m a little worried about the health of Markaby in relation to Rails.
Anyway, I’ll keep plugging and report back here if I work out anything.
Old blog entries
October 14th, 2008
I’ve ported my old blog entries to the new blog and filed them under ‘archive’. Hopefully moving them around won’t have confused anybody.
If you’re wondering, I didn’t use the Mephisto supplied Typo->Mephisto conversion script (see article). I just dumped the previous database, copied the Markdown text, pasted it into new articles and then back-dated them in Mephisto.
blog bootstrap — mephisto on ovh
October 11th, 2008
I thought, for the first entry on my new blog, I’d explain how I got it all up and running. Partly so I will have a reference in the future and partly hoping other people might find it useful.
hosting – ovh
I chose to use a dedicated server from ovh for hosting. I wanted something independent that I had control over and with some reasonable performance. Here’s the configuration I chose:
- ovh config: rsp2
- os distro: linux ubuntu server 8.04.1
- processor: Intel Atom Dual, 2x 1.6 GHz, L2: 2x 512Ko, FSB: 533MHz, Dual-Core
- RAM: 1GB
- storage: 10GB (network attached via. NFS)
- bandwidth: 100Mbps
- throughput limit: none
- 1+1 IP addresses
For me the only real compromise is the network storage instead of dedicated attached disks, but the price was really attractive (€15/month) so I thought I’d see how things go. I’ve noticed that from the command line, disk operations can be kind of slow, but the main purpose of the machine is network services (web, (light) backup, admin, etc.), so I’m hoping that the remote storage won’t be a problem.
I ordered the server on-line on the 7th and it was up and running yesterday (the 10th). So, about a 4 day turn-around. Everything was pretty easy except for one minor hitch – the login ID was wrong on the email they sent to let me know the server was ready. It was admin but should have been root. I guess the other thing that annoyed me slightly was how bear the distro was. I ended up having to install quite a few packages to get a really basic set-up running, but I guess I can’t really disagree with the decision to keep the dristro lean, otherwise you’d potentially end up with a bunch of stuff you don’t need cluttering things up.
blog engine – mephisto
I do a lot of work with Ruby on Rails so I wanted to use, if possible, a blog engine based on Rails. I’ve tried Typo (quite a while ago), and figured I’d play with the new kid on the block and see if he’s any more fun.
Rails deployment
First I had to set up some way to serve up Ruby on Rails. I chose to use Passenger (mod_rails) with Apache’s httpd server. I’ll just create a big list of steps here to give you an idea what I had to do. If you’ve got questions let me know:
apache
1 2 |
sudo apt-get install apache2 sudo apt-get install apache2-threaded-dev |
ruby
1 2 3 4 5 6 7 |
sudo apt-get ruby-full sudo apt-get ruby-pkg-tools # ruby gems -- I chose to install from source to allow ruby gems to update itself cd ~/src wget 'http://rubyforge.org/frs/?group_id=126' cd ~/src/rubygems-1.3.0` sudo ruby setup.rb # see http://www.rubygems.org/read/chapter/3 |
rails
sudo gem install rails` |
passenger
1 2 3 |
sudo gem install passenger sudo passenger-install-apache2-module sudo vi /etc/apache2/mods-available/passenger.conf |
1 2 3 LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3 PassengerRuby /usr/bin/ruby1.8
4 5 |
ln -s /etc/apache/mods-available/passenger.conf /etc/apache/mods-enabled sudo vi /etc/apache/sites-available/default |
1 2 3 4 5 6 7 8 9. . . DocumentRoot /var/www/mephisto/current/public/ <Directory /var/www/mephisto/current/public/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> . . .
mephisto
Setting up mephisto was a little more work than I would have liked. Two things made it complicated:
the TZ environment variable needs to be set and that’s not strait forward for mod_rails. There’s a hack that works, but it’s a bit messy.
the stable version (at the time of writing this) for mephisto is 0.8 which requires rails version 2.0.2 (i.e. mephisto won’t work with newer versions), so I had to freeze mephisto to the 2.0.2 version of rails.
Here’s detailed list of steps I took to get mephisto setup.
1 2 3 4 5 6 7 8 9 10 11 12 |
sudo gem install tzinfo wget http://github.com/technoweenie/mephisto/tarball/master.tar.gz cd /var/www mkdir mephesto cd methisto tar xzf ~/src/technoweenie-mephisto-22dab17c881f9db136194243844d8ace37536099.tar.gz mv technoweenie-mephisto-22dab17c881f9db136194243844d8ace37536099 v0.8 ln -s v0.8 current mkdir shared ; mkdir shared/log; mkdir shared/db cd current sudo su www-data -c 'rake rails:freeze:edge RELEASE=2.0.2' vi config/database.yml |
1 2 3 production: adapter: sqlite3 dbfile: /var/www/mephisto/shared/db/production.sqlite3
13 14 |
rm log; ln -s ../shared/log . rake db:bootstrap |
hack to set TZ environment variable that mephisto needs
1 2 |
sudo mkdir /etc/apache2/passenger sudo vi /etc/apache2/passenger/envronment |
TZ=UTC
sudo vi /etc/apache2/passenger/ruby_with_env |
1 2 3 #!/bin/bash` . $(dirname $0)/environment` /usr/bin/ruby $*
sudo vi /etc/apache2/mods-available/passenger.conf |
1 2 3 4 LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3 #PassengerRuby /usr/bin/ruby1.8 PassengerRuby /etc/apache2/passenger/ruby_with_env