Rails 3.2 を使用しています。以下は私のコントローラーです:
class ShopsController < ApplicationController
...
class << self
Shop::SHOP_TYPES.each do |shop_type|
define_method "nearby_#{shop_type.pluralize}"
@nearby_type = "#{shop_type.pluralize}"
end
end
end
...
end
class Shop < ActiveRecord::Base
SHOP_TYPES = %w(cafe restaurant)
end
しかし、それはsyntax error, unexpected keyword_end, expecting $end
最後に私にend
属しclass ShopsController < ApplicationController
ます。これを手動でコーディングする必要がないように、コードをドライに保とうとしています。
class ShopsController < ApplicationController
...
def nearby_cafes
@nearby_type = "cafes"
end
def nearby_restaurants
@nearby_type = "restaurants"
end
...
end
私は何を間違えましたか?ありがとう。