Skip to content

Instantly share code, notes, and snippets.

@ppworks
Created July 14, 2012 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppworks/3109082 to your computer and use it in GitHub Desktop.
Save ppworks/3109082 to your computer and use it in GitHub Desktop.
routes for current_user
My::Application.routes.draw do
# /my scope for current_user
scope :path => :my do
resources :followings, :only => [:index, :update, :destroy], :as => :my_followings
resources :followers, :only => [:index], :as => :my_followers
resources :feeds, :only => [:index], :as => :my_feeds
resources :groups, :only => [:index], :as => :my_groups do
member do
put :entry, :action => :join
delete :entry, :action => :leave
end
end
delete '' => 'users#destroy'
root :to => 'users#show', :as => :my_root
end
end
@tkawa
Copy link

tkawa commented Jul 16, 2012

書き方の違いだけなのですが、こういうふうにも書けますね。

  resource :my, :controller => :users, :only => [:show, :destroy] do
    resources :followings, :only => [:index, :update, :destroy]
    resources :followers, :only => [:index]
    resources :feeds, :only => [:index]
    resources :groups, :only => [:index] do
      member do
        put :entry, :action => :join
        delete :entry, :action => :leave
      end
    end
  end

@ppworks
Copy link
Author

ppworks commented Jul 16, 2012

scopeより見通し良くみえますね。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment