Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.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 自定义管线生成点而不是';?id=';_Ruby On Rails_Custom Routes - Fatal编程技术网

Ruby on rails 自定义管线生成点而不是';?id=';

Ruby on rails 自定义管线生成点而不是';?id=';,ruby-on-rails,custom-routes,Ruby On Rails,Custom Routes,通过将以下内容添加到my routes.rb,我正在为我的rails应用程序添加custon新操作: resources :adventures do member do match :upvote, via: [:post, :delete] match :downvote, via: [:post, :delete] end get 'seed', on: :new end (你可以忽略投票单,只是想让你看到整个街区) 但这是: seed_new_a

通过将以下内容添加到my routes.rb,我正在为我的rails应用程序添加custon新操作:

resources :adventures do
  member do
    match :upvote, via: [:post, :delete]
    match :downvote, via: [:post, :delete]
  end
  get 'seed', on: :new
end
(你可以忽略投票单,只是想让你看到整个街区)

但这是:

      seed_new_adventure_path(@adventure_collection.id)
生成以下内容:

http://localhost:3000/adventures/new/seed.6
与此相反:

http://localhost:3000/adventures/new/seed?id=6
我读过很多帖子,人们用点代替斜线,但没有一篇是用额外的动作。是我做错了什么,还是我需要添加更多的内容

编辑:我确实犯了一个错误,并不是想增加冒险之路(这是我最初的想法)。真正的问题是,我所需要做的就是将id作为参数传递

以下是我一直在寻找的路径:

  redirect_to seed_new_adventure_path(:id => @adventure_collection.id)

这是因为你使用了错误的多元化

在您的示例中,您正在使用:
seed\u new\u adventures\u path(@adventure\u collection.id)

但这条路线被恰当地描述为:
seed\u new\u adventure\u路径(@adventure\u collection.id)

并且可能工作良好,可读性更强,如下所示:
seed\u new\u advention\u path(@advention\u collection)

这是因为您使用了错误的复数形式

在您的示例中,您正在使用:
seed\u new\u adventures\u path(@adventure\u collection.id)

但这条路线被恰当地描述为:
seed\u new\u adventure\u路径(@adventure\u collection.id)

并且可能工作良好,可读性更强,如下所示:
seed\u new\u advention\u path(@advention\u collection)
路线

尽管
Brad Werth
是正确的(您的路由多元化不正确),但您所面临的最大问题是您正在努力实现的目标

您已指定以下链接:

domain.com/adventure/new/seed
这是一个不存在其他参数的
get
请求。我不明白你为什么要把东西送到这条路线?这就是为什么您会遇到
.6
问题(因为Rails无法构建路由),而不是得到
/6

在考虑了你要做的事情之后,我相信你可以按照如下方式解决它:

#config/routes.rb
resources :adventures do
   ...
   get "seed(/:id)", on: :new #-> domain.com/adventures/new/seed/6
end

路线

尽管Brad Werth是正确的(你的路线多元化是不正确的),但你面临的最大问题是你想要实现什么

您已指定以下链接:

domain.com/adventure/new/seed
这是一个不存在其他参数的
get
请求。我不明白你为什么要把东西送到这条路线?这就是为什么您会遇到
.6
问题(因为Rails无法构建路由),而不是得到
/6

在考虑了你要做的事情之后,我相信你可以按照如下方式解决它:

#config/routes.rb
resources :adventures do
   ...
   get "seed(/:id)", on: :new #-> domain.com/adventures/new/seed/6
end

好的,为了得到这个:

http://localhost:3000/adventures/new/seed?id=7
我需要向链接传递一个参数,如下所示:

  seed_new_adventure_path(:id => @adventure_collection.id)

我只是忘记了如何传递参数

好的,为了得到这个:

http://localhost:3000/adventures/new/seed?id=7
我需要向链接传递一个参数,如下所示:

  seed_new_adventure_path(:id => @adventure_collection.id)

我只是忘记了如何传递参数

如果您将其更改为
seed\u new\u adventures\u path(@adventure\u collection)
您会得到您想要的吗?事实上,新版本上不使用and:id,如rake routes中所示,因此您提供的id将被视为格式。你想用种子做什么?也许应该是:议员?或者在:collection?上,你是想从现有的收藏中植入这个新的冒险吗?很好,我以前不知道
on
方法,如果你把它改成
seed\u new\u adventures\u path(@adventure\u collection)
你得到了你想要的吗?实际上,新的,不需要和:id,如rake routes中所示,因此您提供的id将被视为格式。你想用种子做什么?也许应该是:议员?或者在:collection?上,你是想从现有的系列中播种新的冒险吗?很好,我以前不知道
上的
方法