Rails - How to add a format to an url helper?

fotanus picture fotanus · May 22, 2013 · Viewed 16k times · Source

how can I make an URL helper create an URL in a given request/response format?

For example, in my test I have the following:

get(activity_url(activity))

This will returns me an HTML on the @response object. I'm looking to have the same behavior of the following:

get({controller: 'activities', action: 'show', id: activity.id, format: 'js'})

but without all this wording. Is it possible?

Answer

Marek Takac picture Marek Takac · May 22, 2013

You should be able to do something like this:

some_resource_path(format: :json)

or

some_resource_url(format: :xml)