foodsoft/app/controllers/api/v1/navigations_controller.rb

25 lines
556 B
Ruby
Raw Normal View History

2018-10-13 15:20:27 +02:00
class Api::V1::NavigationsController < Api::V1::BaseController
def show
# we don't use active_model_serializers here, because source is a Hash
render json: { navigation: transform(navigation) }
end
private
def navigation
render_navigation(renderer: :json, as_hash: true)
end
def transform(items)
items.map do |item|
r = {}
r[:name] = item[:name]
r[:url] = request.base_url + item[:url] if item[:url] && item[:url] != '#'
2018-10-13 15:20:27 +02:00
r[:items] = transform(item[:items]) if item[:items]
r
end
end
end