dimanche 22 mai 2016

Change wildcard route based off an array from Rails 3 to Rails 4

In Rails 3, I have these:

# 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

The idea is to generate get routes based off the Shop::TYPES array:

get :cafe
get :restaurant

In any case when I create another new type in Shop, I won't have to update my routes.

I am upgrading to Rails 4. What is the equivalent to get *Shop::TYPES, because I couldn't find the answer?

Aucun commentaire:

Enregistrer un commentaire