11175
(-- --)
July 27, 2008, 6:15pm
1
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.
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")
11175
(-- --)
July 27, 2008, 7:29pm
3
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
One small question regarding the additional parameters, do I need to
declare this somewhere in the routes files?
No, whatever you use like
export_paypal_payments_path(:type => :monthly)
will just end up as params[:type] in your controller