Software Development |
Ruby on Rails
permalink_fu plugin
technoweenie's permalink_fu is one of the plugins used in altered_beast.
This plugin is used to create permalinks from attributes of models. The attribute is escaped to to make it safe to use in a URL in the after_validation callback. You can define a scope for a permalink which effectively makes includes a parent id into the permalink for the child model.
permalinks in altered_beast
Within altered_beast the migration 001_create_permalinks.rb adds permalinks to three already existing tables and attributes:
- Forum.name, for example, http://localhost:3000/forums/tea-making
- Topic.title within Forum, for example, http://localhost:3000/forums/tea-making/topics/ceremony
- User.login within Site
TODO:
- I didn't get User.login permalink working.
Adding a permalink
To add a permalink to you need to update the:
- table schema
- model
You need a migration to add a permalink field to the table:
db/migrate/migration_for_permalink.rb (snippet)
t.string :permalink
In the model you need to specify has_permalink for the appropriate attribute. You also need to include a to_param method returning the permalink.
app/models/model_to_get_permalink.rb (snippet)
has_permalink :attribute_for_permalink def to_param permalink end
