我现在正在使用Ruby on Rails创建一个Web应用程序。
但是,它可能有麻烦。
调用show动作时的路由将显示的文章(文章)当前为hoge.com/articles/ (article id)
。我想/hoge.com/username/(文章ID),但不能完全。
的routes.rb
devise_for :users, controllers: { omniauth_callbacks: 'omniauth_callbacks' }
devise_scope :user do
resources :articles
get '/:username', controller: 'users', action: 'show'
get '/users/sign_out', controller: 'devise/sessions', action: 'destroy'
get 'users/auth/:provider/disconnect', controller: 'omniauth_disconnects', action: 'update'
end
post 'user_invitation_beta_release/new'
get 'static/welcome'
root to: 'root#index'
resources :items
resources :contents
resources :articles do
resources :contents, only: [:create, :destroy, :change_order] do
resources :items, only: [:create, :destroy]
end
end
match "*path" => "application#handle_404", via: :all
请告诉我
答案 0 :(得分:0)
试试这个:
get '/:username/:article_id', controller: 'articles', action: 'show'