Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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路由问题,资源,资源,还是get?_Ruby On Rails_Routing - Fatal编程技术网

Ruby on rails Rails路由问题,资源,资源,还是get?

Ruby on rails Rails路由问题,资源,资源,还是get?,ruby-on-rails,routing,Ruby On Rails,Routing,使用以下路线: resources :locations do resources :newsitems resource :weather get 'weather' end 我没有关于天气的get操作的命名路线: location_weather POST /locations/:location_id/weather(.:format) {:action=>"create", :controller=>"w

使用以下路线:

resources :locations do
  resources :newsitems
  resource :weather
  get 'weather'
end
我没有关于天气的
get
操作的命名路线:

   location_weather POST   /locations/:location_id/weather(.:format)                         {:action=>"create", :controller=>"weathers"}
 new_location_weather GET    /locations/:location_id/weather/new(.:format)                     {:action=>"new", :controller=>"weathers"}
edit_location_weather GET    /locations/:location_id/weather/edit(.:format)                    {:action=>"edit", :controller=>"weathers"}
                      GET    /locations/:location_id/weather(.:format)                         {:action=>"show", :controller=>"weathers"}
                      PUT    /locations/:location_id/weather(.:format)                         {:action=>"update", :controller=>"weathers"}
                      DELETE /locations/:location_id/weather(.:format)                         {:action=>"destroy", :controller=>"weathers"}

我这里怎么了?我把天气作为
获取
资源
放在那里,但我真的想把它作为我的
位置
控制器上的一个动作,因为它实际上不是一个单独的资源。知道我做错了什么吗?

如果天气确实不是一个单独的资源,那么您可能不想在URL中使用它,只需调用locations/:id来检索该位置的天气。然而,如果你正在对地点做其他事情——我猜你是这样的——你可能应该继续为天气创建一个资源。除了show方法之外,它不需要任何东西,但是为了库存和RESTful而使用它是很好的

尝试以下方法。我认为它将为您提供您想要的:

resources :locations do
  matches "weather" => "weather#show"
end

如果天气确实不是一个单独的资源,那么您可能不想在URL中使用它,只需调用locations/:id来检索该位置的天气。然而,如果你正在对地点做其他事情——我猜你是这样的——你可能应该继续为天气创建一个资源。除了show方法之外,它不需要任何东西,但是为了库存和RESTful而使用它是很好的

尝试以下方法。我认为它将为您提供您想要的:

resources :locations do
  matches "weather" => "weather#show"
end

只需删除“资源:天气”即可获得您的位置和天气路线。如果所有这些都是位置控制器上的自定义操作,那么将处理这些操作。

只需删除“资源:天气”即可获得位置和天气路线。如果它只是将处理它的位置控制器上的自定义操作