# Allow downloading Web Service WSDL as a file with an extension
# instead of a file named 'wsdl'
map.connect ':controller/service.wsdl', :action => 'wsdl'
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id.:format'
map.connect ':controller/:action/:id'
rather than specifying the id (which ties you to the particulars of the data that I would personally avoid, but at least the change would be limited to your routes file).
Also, everything is stored generically in my database. I wanted it to
be as flexible as possible. In other words, not everything is going to
be Star Trek, or a TV show, or have characters and episodes.
The entire backend is simply an acts_as_tree Category model and an
Item model. Each category has subcategories, and the subcategories
have items. Who knows, I might want to vote on fruit one day
Anyway, a named route like st_voy_url will never work because I will
never manually link to it. My index page simply iterates over all
categories with items and spits out an unordered list.
Does it make sense what I'm saying and what I'm trying to do?
Two basic options. First you can create a named route:
map.<route_name> 'route', :controller=>...
That way you can build your link_to's, etc using <route_name>_url and
<route_name>_path. You'll probably have to ditch the forward slash in
favor or a dash, however.
Second, you can override the 'to_param' method of ActiveRecord::Base.
By default it returns the id of the record but you can tell it to
return anything... including text. With that in mind I'd suggest
something like this:
class TelevisionSeries
has_many :episodes
has_many :characters
def to_param
name.gsub(/\s+/, '_').dasherize
end
...
end
With that you can use the default RESTfully named routes if you also
nest the routes like so:
map.resources :television_series |tv|
tv.has_many :episodes
tv.has_many :characters
end
The last thing to remember is that you'll receive the dasherized name
of the series in params[:id] so you'll have to operate on it before
attempting to find... and you'll use find_by_name.
Well, I don't think you'll ever be able to get URLs to look as nice that way, but I see what you mean. Have you considered overriding #to_param in your model to be something like a permalink? At least then your URL would be something like:
Well, I don't think you'll ever be able to get URLs to look as nice
that way, but I see what you mean. Have you considered overriding
#to_param in your model to be something like a permalink? At least
then your URL would be something like:
whoa, that link URL actually works I guess you can put anything
you want after the number.
thanks for all the help you guys, I'm not sure what I'll do, but it's
not really a big deal anyways. I might just use named routes and
manually link them.