设计路线中的用户名

时间:2012-11-16 04:23:48

标签: ruby-on-rails-3 devise routes

我努力让用户名显示在与设计相关的路线中。

如何显示以下路线?

www.blabla.com/username/edit
www.blabla.com/username/event/id

我是否必须在范围内声明范围?谢谢你的帮助。

现在我的路线文件看起来像这样

Weplanthings::Application.routes.draw do
  resources :vendors

  resources :venues

  resources :events

  get "profiles/index"

  get "users/index"

  get "users/show"
  get 'tags/:tag', to: 'events#index', as: :tag

   authenticated :user do
     root :to => 'home#index'
   end
   match '/event/new', :to => 'events#new'
   root :to => "home#index"
  devise_for :users do
    get "/login" => "devise/sessions#new"
    match '/login', :to => 'devise/sessions#new'
    get "/logout" => "devise/sessions#destroy"
    match '/logout', :to => 'devise/sessions#destroy'
    get "/edit" => "devise/sessions#edit"
    match '/edit', :to => 'devise/sessions#edit'
    scope ":username", :as => "user" do
      #resources :users
      match '/', :to => 'profiles#index'
      match '/edit', :to => 'devise/sessions#edit'
      match '/event/:id', :to => 'events#show'

    end
  end  

1 个答案:

答案 0 :(得分:1)

我建议您使用friendly_id gem。

只需一行代码即可轻松完成您想要的任务。