Using Rails 3.2. Below is my controller:
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
However, it gives me syntax error, unexpected keyword_end, expecting $end at the very last end belongs to class ShopsController < ApplicationController. I am trying to keep the code dry so that I don’t have to manually code this:
class ShopsController < ApplicationController
...
def nearby_cafes
@nearby_type = "cafes"
end
def nearby_restaurants
@nearby_type = "restaurants"
end
...
end
What have I done wrong? Thanks.
define_methodexpects a block, you’re missing thedoon the line where you calldefine_method