Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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中构造以下JSONAPI url?_Ruby On Rails_Ruby On Rails 4_Json Api - Fatal编程技术网

Ruby on rails 如何在Rails中构造以下JSONAPI url?

Ruby on rails 如何在Rails中构造以下JSONAPI url?,ruby-on-rails,ruby-on-rails-4,json-api,Ruby On Rails,Ruby On Rails 4,Json Api,我在跟踪 我注意到以下终点(路线): 在Rails中,如何在routes.rb中构造此路由 resources :articles do # What goes here? # Should relationship be a namespace or other? # I guess author can be defined as a collection, or just a simple get end 关系不需要7个RESTFUL操作中的任何一个。路由应该类似于以下代码片

我在跟踪

我注意到以下终点(路线):

在Rails中,如何在
routes.rb中构造此路由

resources :articles do
  # What goes here?
  # Should relationship be a namespace or other?
  # I guess author can be defined as a collection, or just a simple get
end

关系
不需要7个RESTFUL操作中的任何一个。

路由应该类似于以下代码片段:

resources :articles do
   resources :relationships, :only => [] do
     collection do 
       get :author
     end
   end
end

这就是路由文件的外观。如果需要任何更新,请告诉我。

路径应类似于以下代码片段:

resources :articles do
   resources :relationships, :only => [] do
     collection do 
       get :author
     end
   end
end

这就是路由文件的外观。如果需要任何更新,请告诉我。

我对关注点的想法受到了质疑,因为您可能需要在多个资源中使用它(the)

这相当于

resources :articles do
  scope :'/relationships' do
    resource :author
  end
end

我对关注点的想法产生了反弹,因为您可能需要在多个资源中使用它(the)

这相当于

resources :articles do
  scope :'/relationships' do
    resource :author
  end
end

作用域:“/relationships”
对我不起作用(至少在Rails 5中是这样)

我用这个来工作:

resources :articles do
  resources :author, path: 'relationships/author'
end

这将只使用
AuthorController
并将其映射到
/articles/:id/relationships/author
范围:“/relationships”
对我不起作用(至少在Rails 5中是这样)

我用这个来工作:

resources :articles do
  resources :author, path: 'relationships/author'
end

这将只使用
AuthorController
并将其映射到
/articles/:id/relationships/author

取决于,您是否有许多其他资源将位于
/relationships
下?您关联的控制器(子文件夹)在哪里?您的控制器操作是什么?可能不是,所以我猜
namespace:relationships;获取“作者”;结束应该可以。这也意味着
get'author'
路径将指向
ArticlesController
中的
author
操作。除非有办法使
作者
操作存在于
关系
控制器中,否则?我认为这有助于更好的逻辑抽象也许值得研究一下,如果你可以使用,因为这是你可以为许多其他资源重用的东西,在APIdepends的上下文中,你是否有许多其他资源可以归入
/关系
?您关联的控制器(子文件夹)在哪里?您的控制器操作是什么?可能不是,所以我猜
namespace:relationships;获取“作者”;结束应该可以。这也意味着
get'author'
路径将指向
ArticlesController
中的
author
操作。除非有办法使
作者
操作存在于
关系
控制器中,否则?我认为这有助于更好的逻辑抽象也许值得研究一下,如果你可以使用,因为在APII进行编辑的背景下,这可能会被重用为许多其他资源,因此
关系
路由不充当资源(即无索引、显示等)。并显式地为它指定一个控制器,使它驻留在
文章
文件夹中对不起,我没有清楚地得到您的评论。你能更准确地解释你的问题吗?你最初的回答是正确的。只是一些建议。只需指定
resources:relationships
即可公开
关系的7个RESTFUL操作(索引、显示、新建、更新等)。如果没有
控制器:'articles/relationships'
作者
操作将存在于
关系#作者
中,而不是
文章/关系#作者
中。我想我应该指出这一点,这样关系就不需要公开任何restful操作了,对吗?是的,让我更新我的初始问题以明确这一点。我做了一次编辑,所以
关系
路由不作为资源(即没有索引、显示等)。并显式地为它指定一个控制器,使它驻留在
文章
文件夹中对不起,我没有清楚地得到您的评论。你能更准确地解释你的问题吗?你最初的回答是正确的。只是一些建议。只需指定
resources:relationships
即可公开
关系的7个RESTFUL操作(索引、显示、新建、更新等)。如果没有
控制器:'articles/relationships'
作者
操作将存在于
关系#作者
中,而不是
文章/关系#作者
中。我想我应该指出这一点,这样的关系就不需要暴露任何平静的行为了,对吗?是的,让我更新我的初始问题来阐明这一点