Sha256: 245f84d71e7e307ef986533014dd22783f2a7d05b1e304443a9aba2a6f30d138
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
module Carload module ApplicationHelper def needs_upload? model_name, attribute_name case Carload.upload_solution when :carrierwave model_class = model_name.to_s.classify.constantize not model_class.instance_methods.map(&:to_s).select { |x| x =~ /#{attribute_name}_url/ }.empty? end end def polymorphic? attribute_name Dashboard.model(@model_name).associations.each_value do |association| reflection = association[:reflection] return reflection.name if attribute_name =~ /#{reflection.name}/ and reflection.options[:polymorphic] end false end def image? model_name, attribute_name attribute_name.to_s =~ /image|logo|img/ or (Dashboard.model(model_name).attributes.images.include? attribute_name.to_sym rescue nil) end def associated_model_name model_name, attribute_name x = attribute_name.gsub(/_ids?$/, '').to_sym Dashboard.model(model_name).associations.each do |name, association| return association[:class_name] || x, name if name.to_s.singularize.to_sym == x end raise 'Should not go here!' end def id_or_ids reflection case reflection when ActiveRecord::Reflection::HasManyReflection "#{reflection.name.to_s.singularize}_ids" else "#{reflection.name}_id" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
carload-0.5.3 | app/helpers/carload/application_helper.rb |
carload-0.5.2 | app/helpers/carload/application_helper.rb |