class TagController < ApplicationController
def show
@videos = Video.tagged_with(params[:id])
respond_to do |format|
format.html # show.html.erb
end
end
end
日志:
Started GET "/tag/node.js" for 127.0.0.1 at 2011-06-13 23:10:59 +0100
Processing by TagController#show as JS
Parameters: {"id"=>"node"}
目前我正在传递node.js
作为params[:id]
的值,但不知何故(根据日志)我的应用仅传递node
作为参数值。
如何确保将值node.js
传递给我的控制器?
提前致谢。
答案 0 :(得分:2)
啊,路由中的(.:format)
被Rails吃掉了; .js
用于确定格式。
因此,对此的一个简单修复可能是:
respond_to do |format|
format.html # show.html.erb
format.js { render <erb file used for html> }
end
但是,这并没有“感觉”正确,因为您使用format
返回的内容不是那种格式(我们在请求.js
时返回HTML)
如果可以,您应该将“node.js”更改为其他值,例如“node_js”。否则,请查看使用parse_query
or parse_nested_query
in Rack。
或者您可以定义/重新定义路线,但不会将(.:format)
添加到最后。