0

親からテーブルとコントローラーを継承するリソースがあります。その親には、渡したいカスタム ルーティングもありますが、その方法 (または可能かどうか) はわかりません。現在、ルートは次のようになっています。

resources :publications do
  resources :editions, :controller => :publications
  collection do
    get :autocomplete, :claim, :current_users_publications, :lightbox, :lookup
    post :review
  end
  member do
    get :audit, :reassign_prompt
    post :approve, :audit_vote
    put :reassign
  end
end

現在の設定では、エディション モデルは「監査」や「オートコンプリート」などのカスタム メソッドにアクセスできません。「:routes => :publications」のようなことは可能ですか?

4

1 に答える 1

1

ルーティングの問題を確認する

# Define the concern
concern :somethingable do
  collection do
    get :autocomplete, :claim, :current_users_publications, :lightbox, :lookup
    post :review
  end
  member do
    get :audit, :reassign_prompt
    post :approve, :audit_vote
    put :reassign
  end
end

# And now your routing
resources :publications, concerns: :somethingable do
  resources :editions, controller: :publications, concerns: :somethingable
end

:somethingable一般的な動作を説明するよりも適切な用語を考えられると思います

アップデート

上記はレールmasterブランチ用であるため、利用できる代替手段がいくつかあります

  1. Rails 3.2+ で使用するために、この動作を抽象化するgemがあります。
  2. を使用する代わりにconcern、ルーティング ファイルにメソッドを作成するだけです。

    def somethingable
      collection do
        get :autocomplete, :claim, :current_users_publications, :lightbox, :lookup
        post :review
      end
      member do
        get :audit, :reassign_prompt
        post :approve, :audit_vote
        put :reassign
      end
    end
    

    あなたのルートは次のようになります

    resources :publications do
      somethingable
    
      resources :editions, controller: :publications do
        somethingable
      end
    end
    
于 2012-11-27T20:21:31.460 に答える