This project is archived and is in readonly mode.
Polymorphic routes, :as => "polymorphic_name"
-
Andrew White
- State changed from new to wontfix
- Importance changed from to Low
The polymorphic_path helper is designed to build route names from the class name of the object passed to it with. Therefore if you pass it a message object then that's what it will use - it doesn't look at the application's routes, it just calls the route helper name that it builds from the arguments. You may want to look at refactoring your routes to something like this:
# config/routes.rb resources :users do resources :messages, :except => :index do collection do get :received get :sent post :send end member do post :send end end endThen in MessagesController you can implement the custom actions for received messages, sent messages and sending a message directly or after saving a draft. This way you can map the standard REST actions like new, create, edit, update to dealing with drafts. The destroy action would then either delete an unsent draft message or delete the link record from the appropriate table depending on whether it's a sent or received message.
-
ifesdjeen
Thanks, Andrew, will try to do so
-
ifesdjeen
BTW, Andrew, it does look at the application routes, moreover it matches all arguments you pass.
Actually, what I was trying to implement, is also on top of Inherited Resources.Inherited Resources is picking up child objects with polymorphic connections.
The other problem I ran into in Rails itself, is that polymorphic_path([user, "sent_messages"]) generates an error, that's saying that :destroy action is missing for SentMessages controller, even though it's present in routes. It was caused by further check in Rails, that checks if the model is not persisted, it pops it out of the hash. And that produces an unmatched route.What you say is completely valid, but letting 2 controllers to be polymorphic in a way, that's quite close to models polymorphic behavior, I may get a bit more out of it all.
Thank you for participation again