Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails-如何向url帮助器添加格式?_Ruby On Rails_Request_Helper_Url Helper - Fatal编程技术网

Ruby on rails Rails-如何向url帮助器添加格式?

Ruby on rails Rails-如何向url帮助器添加格式?,ruby-on-rails,request,helper,url-helper,Ruby On Rails,Request,Helper,Url Helper,如何让URL助手以给定的请求/响应格式创建URL 例如,在我的测试中,我有以下几点: get(activity_url(activity)) get({controller: 'activities', action: 'show', id: activity.id, format: 'js'}) 这将返回@response对象上的HTML。我希望有以下相同的行为: get(activity_url(activity)) get({controller: 'activities', act

如何让URL助手以给定的请求/响应格式创建URL

例如,在我的测试中,我有以下几点:

get(activity_url(activity))
get({controller: 'activities', action: 'show', id: activity.id, format: 'js'})
这将返回
@response
对象上的HTML。我希望有以下相同的行为:

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

但没有这些措辞。可能吗?

您应该能够执行以下操作:

some_resource_path(format: :json)


我对Rails/Ruby相当陌生,所以我不知道为什么,但在我的Rails 3.2应用程序中,语法必须是:

some_resource_path(:format => :json)

谢谢,这是最后一个参数。你知道在哪里可以找到这个url帮助程序的文档吗?一个简短的语法“some\u resource\u path:json”很有效,你是说
:format=>:json
?它与
format::json
相同,但有一些额外的语法。但是,
format:=>:json
似乎是语法错误。