Hi, I''m trying to implement some charts in my REST application. But I can''t seem to use an extra action like "chart" in my controller. Becouse of the rest approach, it sees the action name as an id. Does anyone know how to overcome this? So that I can visit the charts page of a sertain resource like /resource/charts ? I know I could create a new controller and not adding it to the resources in the routes file, but I would like to have the carts in the resource controller, becouse in my opinion, the carts view belongs to the resource. Thank you in advance. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I''m trying to implement some charts in my REST application. But I can''t seem to use an extra action like "chart" in my controller. Becouse of the rest approach, it sees the action name as an id. Does anyone know how to overcome this? So that I can visit the charts page of a sertain resource like /resource/charts ? Thank you in advance. -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
define your routes like this: map.resources :payments, :collection => [:export_paypal], :member => [:print_pdf] the difference between collection & member is, that collections work on all items of that resource (no id needed, like index action), so export_paypal_payments_path() could be used and give you a list of all payments while a member works on a single item of the resource, defined by it''s id print_pdf_payment_path(1234) would print the payment with id 1234 as pdf of course like with all other REST actions (or CRUD actions, to be correct) you can use additional named params like: export_paypal_payments_path(:type => :monthly) print_pdf_payment_path(1234, :font => "Arial") --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thorsten Mueller wrote:> you can use additional named params like: > > export_paypal_payments_path(:type => :monthly) > print_pdf_payment_path(1234, :font => "Arial")Thank you Thorsten for your quick reply. You answer helped me a lot. One small question regarding the additional parameters, do I need to declare this somewhere in the routes files? Thank you again for the help -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The first option is to make a completely new controller for charts. The index action would list all available charts and the show action lists the specific chart. That is the most RESTful approach Another option would be to modify the show action so that it shows the chart. /foo/1.png => displays the chart Finally, if you absolutely must, you can use a :member action map.resource :foos, :member => {:chart => :get} /foos/1/chart or map.resource :foos, :collection => {:charts => :get} /foos/charts A "collection" is like a list view - dealing with multiple objects A "member" is for dealing with a specific object. On Sun, Jul 27, 2008 at 1:10 PM, D@ Mick <michael.rigart-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I''m trying to implement some charts in my REST application. But I > can''t seem to use an extra action like "chart" in my controller. > Becouse of the rest approach, it sees the action name as an id. > > Does anyone know how to overcome this? So that I can visit the charts > page of a sertain resource like /resource/charts ? > > I know I could create a new controller and not adding it to the > resources in the routes file, but I would like to have the carts in > the resource controller, becouse in my opinion, the carts view belongs > to the resource. > > Thank you in advance. > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---