If I have a resource called ''assets'' then I get for free a bunch of helpers, like assets_path new_asset_path and so forth, right? I would like to be able to create a call to one of these on the fly when I only find out the name of the resource at run time. For example I would like to do this: resource_name = "assets" resource_path(resource_name, method => :new) Anyone know the Rails/Rest/Routing incantation for that? Thanks! Pito -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Nov 1, 4:40 pm, Pito Salas <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I would like to be able to create a call to one of these on the fly when > I only find out the name of the resource at run time. For example I > would like to do this: > > resource_name = "assets" > resource_path(resource_name, method => :new) > > Anyone know the Rails/Rest/Routing incantation for that? Thanks!I believe you are looking for the "url_for" helper. Probably a number of ways you can use it. This one works, and uses the named "new_asset" route. Just make sure resource_name is singular. url_for(("new_"+resource_name).to_sym) Or if the controllers have the standard REST naming, this should also work: url_for(:controller=>resource_name, :action=>:new) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I found this, which I think is going to work ActionDispatch::Routing::PolymorphicRoutes In: actionpack/lib/action_dispatch/routing/polymorphic_routes.rb: "Polymorphic URL helpers are methods for smart resolution to a named route call when given an Active Record model instance. They are to be used in combination with ActionController::Resources. These methods are useful when you want to generate correct URL or path to a RESTful resource without having to know the exact type of the record in question. Nested resources and/or namespaces are also supported, as illustrated in the example: polymorphic_url([:admin, @article, @comment]) results in: admin_article_comment_url(@article, @comment) " Thanks! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Reasonably Related Threads
- [PATCH v1] virtio-mem: add memory via add_memory_driver_managed()
- [PATCH v1] virtio-mem: add memory via add_memory_driver_managed()
- [PATCH v1 2/3] mm/memory_hotplug: Introduce MHP_DRIVER_MANAGED
- [PATCH v1 2/3] mm/memory_hotplug: Introduce MHP_DRIVER_MANAGED
- [PATCH v2 2/3] mm/memory_hotplug: Introduce MHP_NO_FIRMWARE_MEMMAP