jumph4x/canonical-rails

Resource Aliasing

Closed this issue · 4 comments

I have an events resource, and created an alias route for 'e'. How can I make the canonical route the full resource name, events?

Rails.application.routes.draw do
  resources :events  
  resources :e, controller: 'events'
end

Also, I'm not sure I understand the config.collection_actions = []. What options are available to go into that array?

I modified my aliasing to be more generalized and to avoid this canonical issue. Still have the question about collection_actions.

Rails.application.routes.draw do
  #alias the "events" routes
  match '/e/*other',
    via: :all,
    to: redirect { |path_params, req|
      #We are matching /e from an absolute path. Thus, the first occurrence of '/e' is the one we want to substitute for '/events'. Sub the first and return
      req.original_url.sub('/e','/events')
    }

  #...other stuff...
end

@JarLowrey config.collection_actions is simply a way to specify which actions (aka controller methods) represent collections of objects. As in, which actions render multiple objects, so traditionally this would be the [:index] action.

All it's used for is adding a trailing slash to the URL, as per the unix convention, which would imply a directory. When one chooses and end-leaf node, such as a blogpost, there would be no trailing slash to indicate a file or a final destination in the Unix convention.

The SEO benefit from this is now wither negligible or completely gone, but back in the day, there was speculation that this actually helped things.

TL;DR: Don't worry, be happy.

Ah ok I got it now, thanks!

Welcome!