2009-07-03 23 views
1

このようなパスをマップするルートを作成するにはどうすればよいですか?ネストしたルーティング

これは私がこれまでに得たものである

/パワーユーザー/ボブ/記事タイトル

map.resources :users, :as => "powerusers" do |users| 
    users.resources :articles, :as => '' 
end 

これは私に次のルートを与える:

/パワーユーザー/:user_idは//: id

どのようにしてダブルバックラを取り除くことができますか?/powerusers/admin // first-article?

よろしくお願いいたします。 AsbjørnMorell

答えて

4

中級のネストされたリソース(/ articles)が必要ない場合は、map.resourcesをまったく使用しません。

試してみてください。

map.connect '/powerusers/:user_id/:article_title', :controller => 'articles', :action => 'view_by_title' 
+0

は私に与えます"、:action =>" show "}:/ – atmorell

+0

甘い:)ありがとう。 – atmorell

+0

うれしい私は助けることができました! –

1

私が追加した場合は...

map.resources :users, :as => "powerusers" do |users| 
    users.resources :entries, :as => 'article-title' 
    end 

私はあなたが欲しいものを含め、以下のルートを、取得...

(代替 "記事"あなたの状況のた​​めの「エントリー」のため)。

   GET /powerusers(.:format)         {:controller=>"users", :action=>"index"} 
       POST /powerusers(.:format)         {:controller=>"users", :action=>"create"} 
       GET /powerusers/new(.:format)        {:controller=>"users", :action=>"new"} 
       GET /powerusers/:id/edit(.:format)      {:controller=>"users", :action=>"edit"} 
       GET /powerusers/:id(.:format)        {:controller=>"users", :action=>"show"} 
       PUT /powerusers/:id(.:format)        {:controller=>"users", :action=>"update"} 
       DELETE /powerusers/:id(.:format)        {:controller=>"users", :action=>"destroy"} 
    user_entries GET /powerusers/:user_id/article-title(.:format)   {:controller=>"entries", :action=>"index"} 
       POST /powerusers/:user_id/article-title(.:format)   {:controller=>"entries", :action=>"create"} 
new_user_entry GET /powerusers/:user_id/article-title/new(.:format)  {:controller=>"entries", :action=>"new"} 
edit_user_entry GET /powerusers/:user_id/article-title/:id/edit(.:format) {:controller=>"entries", :action=>"edit"} 
    user_entry GET /powerusers/:user_id/article-title/:id(.:format)  {:controller=>"entries", :action=>"show"} 
       PUT /powerusers/:user_id/article-title/:id(.:format)  {:controller=>"entries", :action=>"update"} 
       DELETE /powerusers/:user_id/article-title/:id(.:format)  {:controller=>"entries", :action=>"destroy"} 
+0

これは私が探しているURLです:/powerusers/:user_id/:id(.:format)あなたの例では2番目のコントローラ名 - article-titleを非表示にしたい – atmorell

1

入れ子の代わりに、これは機能しますか? /powerusers/:user_id/admin/:id(.:format){::コントローラ=> "記事を

私はそれがなく、簡単なテストが良く言うだろうではないだろうと思います:)

+0

ちょうど試してみて、結果は/ powerusers /です:私はurlから記事を取り除こうとしています。user_id/articles /:id(。:format){:controller => "articles"、:action => "show"} – atmorell

+0

私はちょうどここにアイデアを投げています(私は何を話しているのか分かりません)。あなたは試しましたか?as => ''の代わりにas => nil? –

+0

np :) Jep、試してみた:as => nil/false。 – atmorell

関連する問題