Param变量为string

时间:2016-04-11 20:24:57

标签: ruby-on-rails ruby

转换它的最佳方式是:id变量 @object = Object.find(params[:id])

成一个字符串?

render :json => {"status" => "404", "message" => "Object with id " + ":id" + " not found"}

也尝试过:

render :json => {"status" => "404", "message" => "Object with id #{:id} not found"}

但它给出了这个错误:

  

没有将符号隐式转换为字符串

1 个答案:

答案 0 :(得分:3)

只需将#{:id}替换为"#{params[:id]}"

即可