Stuff I done learned about Hobo
In which I discover things, sometimes painfully.
Unless otherwise stated, done using Ruby 1.9.2, Hobo 1.0.3 (and hence Rails 2.3.10):
It seems that permissions in Hobo can be a little tricky, in so much as I've had a case where something that behaved appropriately under a test environment, starting throwing permissions errors under development. In particular, the error “view of non-viewable field 'foo'” seemed to trigger problems where a link or foreign key field caused problems. Issues included:
Test for a guest then an admin then for user properties: otherwise the admin may fail on the user properties.
Write a permission method for the specific field: e.g.:
def poster_view_permitted? true end
Check the permissions on the referred class
You can call “server” with -p to set the port and -P to set the path, so you can test serving the site at a subdomain:
.script/server -p 9123 -P /saird
You can pass an environment via -e or set the env with a bash call. This is useful for testing the production version:
RAILS_ENV=production ./script/server -e production
Do the migration of the production database from your development environment in a similar way:
RAILS_ENV=production rake db:migrate
Generate with -p to “pretend” (don't actually make the changes):
./script/generate hobo_migration -p
DRYML is sufficiently strange that if you want to customize the appearance, it can be hard to know where to start. Some tips:
1. Copy the appropriate template of another object, delete the object specific features and use
- Copy the auto-generated template from app/views/taglibs/auto/rapid
- Use the psuedo tags
% ./script/plugin remove more % script/plugin install git://github.com/cloudhead/more.git
and regenerating the stylesheets manually:
% rake more:generate
"wrong number of arguments"
After creating a new model class and editing it, the subsequent migration failed with a cryptic error:wrong number of arguments (1 for 2). Calling the generator with traceback enabled, pointed out the new class as the error:
./script/generate hobo_migration -t
That's because the ”:required” keyword on a field was spelt ”:requires”:
fields do description :text, :requires end
Changed and fixed. Easy.
The DRYML parser is far less forgiving than your typical web browser - it has to be legalXML. So while a browser will put up with this:
<input type="hidden" name="submitted" value="true">
Hobo insist that it be like this:
<input type="hidden" name="submitted" value="true" />
Permissions on subordinate objects
Discovered by Ali and recorded for when we encounter this again.
A strange situation arose in the creation of a Hobo model that had children that were another model that could be created inline, a classic one-to-many:
class Foo < ActiveRecord::Base hobo_model # Don't put anything above this [...] has_many :bars, :accessible => true, :dependent => :destroy
class Bar < ActiveRecord::Base hobo_model # Don't put anything above this [...] belongs_to :foo
The aim was to allow users to create a Foo, with a variable number of children Bars created inline on the same form. Users would be unable to later edit or delete these objects. Thus permissions were set allowing non-admin users to create Foos and Bars but other actions were denied.
After a great deal of trial and error, the problem was identified. Non-admin users require the destroy permission for the bar children to appear, even on a form for the de novo creation of Foo. Perhaps this is because the child delete (minus) button requires this permission. Perhaps it's because the new form and edit forms are one and the same. More investigation is required.