36

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?

fotanus
  • 19,618
  • 13
  • 77
  • 111

2 Answers2

57

You should be able to do something like this:

some_resource_path(format: :json)

or

some_resource_url(format: :xml)
Marek Takac
  • 3,002
  • 25
  • 30
0

I'm fairly new to Rails/Ruby, so I'm not sure why, but in my Rails 3.2 application the syntax must be eg:

some_resource_path(:format => :json)
  • 1
    did you mean `:format => :json`? It is the same than `format: :json`, but with some extra syntax sugar. However, `format: => :json` seems like a syntax error. – fotanus Dec 07 '14 at 02:53