ruby-on-railsrequesthelperurl-helper

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


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?


Solution

  • You should be able to do something like this:

    some_resource_path(format: :json)
    

    or

    some_resource_url(format: :xml)