Frage

Ich möchte einen Weg in meine Rails-Anwendung erstellen entlang der Linien von

/panda/blog
/tiger/blog
/dog/blog

wo Panda, Tiger und Hund sind alle Permalinks (für ein Tier-Klasse)

Der normale Weg, dies zu tun

map.resources :animals do |animal|
 animal.resource :blog
end

schaffen würden Routen entlang der Linien von

/animals/panda/blog
/animals/tiger/blog
/animals/dog/blog

Aber ich will nicht das erste Segment, wie es immer das gleiche sein wird.

Ich weiß, dass ich dies durch manuelles Routing tun könnte, aber ich möchte wissen, wie Ressourcen Schienen zu tun, wie Tiere und Blogs ist eine Voraussetzung für mich zu haben.

War es hilfreich?

Lösung

In Schienen 3.x können Sie path => "" einen resource oder resources Anruf hinzufügen, das erste Segment aus dem erzeugten Pfad zu entfernen.

resources :animals, :path => ""

$ rake routes

    animals GET    /                   {:action=>"index", :controller=>"animals"}
            POST   /                   {:action=>"create", :controller=>"animals"}
 new_animal GET    /new(.:format)      {:action=>"new", :controller=>"animals"}
edit_animal GET    /:id/edit(.:format) {:action=>"edit", :controller=>"animals"}
     animal GET    /:id(.:format)      {:action=>"show", :controller=>"animals"}
            PUT    /:id(.:format)      {:action=>"update", :controller=>"animals"}
            DELETE /:id(.:format)      {:action=>"destroy", :controller=>"animals"}

Andere Tipps

Sie können dieses Plugin verwenden:

http://github.com/caring/default_routing/tree/master

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top