使用 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
我做错了什么?谢谢。