使用"生成my_model_path?"和"&"而不是" /"

时间:2017-02-13 11:44:34

标签: ruby-on-rails ruby

我在路线中有这个:

get 'entities/:var1/:var2' => 'entities#show'

但是这个:

entities_path(var1: "fdsfds", var2: "fdsfdsfdsfds")

生成一个网址?和&amp ;.这是为什么?为什么不用" /"?

1 个答案:

答案 0 :(得分:1)

routes.rb

中添加此路线
get 'entities/:var1/:var2', to: 'entities#show', as: 'custom_entities'

并用

调用它
custom_entities_path("fdsfds", "fdsfdsfdsfds")

现在生成

entities/fdsfds/fdsfdsfdsfds

现在你会得到

params[:var1] = "fdsfds"
# and 
params[:var1] = "fdsfdsfdsfds"