
byte[] 

Philomena Contributor
@LightningBolt
Phoenix has trouble with "bare" or "constrained" URL formats.
Previously, Rails allowed us to do this:
However, because Phoenix has a completely different method for matching routes (it can only use a fixed string prefix), the best we can do with the Phoenix router (outside of hijacking the request pipeline) is this:
(Note that this is also why you can't go to
Furthermore, it wasn't compatible with our resourceful routing scheme. You may have previously noticed this inconsistency on the Rails side, where routes like
These are the reasons I am moving to this canonical format. To me, with the new framework, it doesn't make any sense anymore to keep
Phoenix has trouble with "bare" or "constrained" URL formats.
Previously, Rails allowed us to do this:
constraints(id: /[0-9]+/) do
get '/:id' => 'images#show', :as => 'short_image'
get '/next/:id' => 'images#navigate', :as => 'next_image', :do => 'next'
get '/prev/:id' => 'images#navigate', :as => 'prev_image', :do => 'prev'
get '/find/:id' => 'images#navigate', :as => 'find_image', :do => 'find'
end
constraints(id: /[a-z]+/) do
get ':id', controller: 'forums', action: 'show'
get '/:id' => 'forums#show', as: 'short_forum'
end
constraints(forum_id: /(?!users)(?!pages)(?!thumbs)(?!media)[a-z]+/) do
get '/:forum_id/:id' => 'topics#show', as: 'short_topic'
get '/forums/:forum_id/:id' => 'topics#show'
get '/:forum_id/topics/:id' => 'topics#show'
get '/:forum_id/:id/last' => 'topics#show_last_page'
get '/forums/:forum_id/topics/:id/last' => 'topics#show_last_page'
get '/:forum_id/topics/:id/last' => 'topics#show_last_page'
constraints(page: /[0-9]+/) do
get '/:forum_id/:id/:page' => 'topics#show'
get '/:forum_id/topics/:id/:page' => 'topics#show'
end
get '/:forum_id/:id/post/:post_id' => 'topics#show', as: 'short_topic_post'
get '/:forum_id/topics/:id/post/:post_id' => 'topics#show'
end
However, because Phoenix has a completely different method for matching routes (it can only use a fixed string prefix), the best we can do with the Phoenix router (outside of hijacking the request pipeline) is this:
get "/:id", ImageController, :show
# get "/:forum_id", ForumController, :show # impossible to do without constraints
get "/:forum_id/:id", TopicController, :show
get "/:forum_id/:id/:page", TopicController, :show
get "/:forum_id/:id/post/:post_id", TopicController, :show
(Note that this is also why you can't go to
/dis
anymore to get the General Discussion forum. You have to go to /forums/dis
now.) Furthermore, it wasn't compatible with our resourceful routing scheme. You may have previously noticed this inconsistency on the Rails side, where routes like
/:image_id/tag_changes
did not exist, and were always pointed to /images/:image_id/tag_changes
. The same thing applies here. These are the reasons I am moving to this canonical format. To me, with the new framework, it doesn't make any sense anymore to keep
/:id
as the canonical route.