2012-11-16 66 views
0

我很努力獲取用戶名顯示在與設計相關的路線。用戶名在路由與設計

如何獲得以下路線以顯示?

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

我的建議是你使用friendly_id寶石。

這將使你更容易做到你想要的,只需一行代碼。