lib/locomotive/custom_fields.rb in locomotive_cms-2.0.3 vs lib/locomotive/custom_fields.rb in locomotive_cms-2.1.0

- old
+ new

@@ -1,17 +1,17 @@ # Custom options for CustomFields CustomFields.options = { - :reserved_names => Mongoid.destructive_fields + %w(created_at updated_at) + reserved_names: Mongoid.destructive_fields + %w(created_at updated_at) } module CustomFields class Field include Locomotive::Mongoid::Presenter - field :ui_enabled, :type => Boolean, :default => true + field :ui_enabled, type: Boolean, default: true def class_name_to_content_type self._parent.send :class_name_to_content_type, self.class_name end @@ -43,16 +43,23 @@ # In some situations, for instance, for the notification email when a content entry is created, # we need to know the url of the file without breaking the upload process. # Actually, the uploaded file will be written on the filesystem after the email is sent. # + # @param [ String ] host Required to build the full url in the Filesystem is used (optional) + # # @return [ String ] The url to the soon uploaded file # - def guess_url + def guess_url(host = nil) this = self.class.new(model, mounted_as) this.retrieve_from_store!(model.read_uploader(mounted_as)) - this.url.to_s + + if this.url =~ /^http/ || host.blank? + this.url + else + URI.join("http://#{host}", this.url).to_s + end end def cache_dir "#{Rails.root}/tmp/uploads" end @@ -60,7 +67,6 @@ end end end -end - +end \ No newline at end of file