19 lines
656 B
Ruby
19 lines
656 B
Ruby
|
module Admin::VideoProgramsHelper
|
||
|
def cal_url_to_show(module_app, model)
|
||
|
pages = Page.where(:module=>module_app.key).order_by(id: :asc)
|
||
|
if model.respond_to?(:category_id) && model.category_id
|
||
|
pages = pages.any_of({:categories.in => ['all', model.category_id.to_s]}, {:categories=> {'$size'=> 0}})
|
||
|
end
|
||
|
puts "pages = #{pages}"
|
||
|
|
||
|
page_data_list = pages.pluck(:url, :categories).sort_by{|page_data|
|
||
|
page_data[1].length == 1 && page_data[1] != 'all' ? 0 : 1
|
||
|
}
|
||
|
|
||
|
if page_data_list
|
||
|
show_page_url = page_data_list[0][0]
|
||
|
return "/#{I18n.locale}#{show_page_url}/#{model.to_param}"
|
||
|
end
|
||
|
return '#'
|
||
|
end
|
||
|
end
|