Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.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 3更改为Rails 4_Ruby On Rails_Ruby On Rails 3_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 将基于数组的通配符路由从Rails 3更改为Rails 4

Ruby on rails 将基于数组的通配符路由从Rails 3更改为Rails 4,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,在Rails 3中,我有以下内容: # shop.rb class Shop < ActiveRecord::Base TYPES = %w(cafe restaurant) end # shops_controller.rb class SpotsController < ApplicationController def cafe end def restaurant end end # routes.rb resources :shops do r

在Rails 3中,我有以下内容:

# shop.rb
class Shop < ActiveRecord::Base
  TYPES = %w(cafe restaurant)
end

# shops_controller.rb
class SpotsController < ApplicationController
  def cafe
  end

  def restaurant
  end
end

# routes.rb
resources :shops do
  resources :reviews, :photos
  member do
    get *Shop::TYPES
  end
end
在任何情况下,当我在
商店
中创建另一个新类型时,我都不必更新路线

我正在升级到Rails 4。因为我找不到答案,所以什么等效于
get*Shop::TYPES

resources :shops do
  resources :reviews, :photos
  member do
    get 'cafe'
    get 'restaurant'
  end
end
你也可以试试这个

resources :shops do
  resources :reviews, :photos
  member do
    get 'cafe'
    get 'restaurant'
  end
end

当您在rails 4中使用通配符时,也可以尝试此操作。是否看到错误?如果是,您可以共享输出吗?只是一个想法(未经测试)如果您使用类似于
Shop::TYPES.each do | type |
的东西在数组中进行迭代会怎么样?并使用它使
获取“/#{type}”
?@codingaw的附加输出无法启动应用程序。没有太多有用的堆栈跟踪。那就是我使用相同的rails 3代码的时候了。@codingaddition我不想这样迭代。因为如果我可以在Rails 3中使用这种语法,那么Rails 4肯定还有另一种语法。好吧,我发现你的问题很有趣,我正在深入研究Rails代码,看看是否可以找到相关的东西:当你在Rails 4中使用通配符时,你看到错误了吗?如果是,您可以共享输出吗?只是一个想法(未经测试)如果您使用类似于
Shop::TYPES.each do | type |
的东西在数组中进行迭代会怎么样?并使用它使
获取“/#{type}”
?@codingaw的附加输出无法启动应用程序。没有太多有用的堆栈跟踪。那就是我使用相同的rails 3代码的时候了。@codingaddition我不想这样迭代。因为如果我能在Rails 3中使用这种语法,那么Rails 4肯定还有另一种语法。好吧,我发现你的问题很有趣,我正在深入研究Rails代码,看看是否能找到相关的东西:我想要动态的。我想要动态的。