当前路线已定义为:
Rails.application.routes.draw do
namespace :users do
resources :mapps
resources :listings
resources :likes
get 'followers' => 'connections#followers'
get 'following' => 'connections#following'
post 'unfollow' => 'connections#unfollow'
end
get ':username' => 'users#public_profile'
end
我想制作像facebook这样的路线:
:username/:controller/:action => users/:controller/:action
例如,如果用户将URL命名为/ myusername / posts / 12,则请求必须转到用户文件夹内的控制器文件&用户:帖子
我见过许多相关问题,但没有使用Rails 4.2.3
答案 0 :(得分:1)
来自http://guides.rubyonrails.org/routing.html#prefixing-the-named-route-helpers
的示例scope ':username' do
resources :mapps
resources :listings
resources :likes
get 'followers' => 'connections#followers'
get 'following' => 'connections#following'
post 'unfollow' => 'connections#unfollow'
end