Clase para las propuestas ciudadanas
# File app/models/proposal.rb, line 103 def attached_files(lang=I18n.locale) self.attachments end
See thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip#comment-2415
# File app/models/proposal.rb, line 53 def attachment_for name @_paperclip_attachments ||= {} @_paperclip_attachments[name] ||= Attachment.new(name, self, self.class.attachment_definitions[name]) end
Indica si este documento tiene documentos adjuntos
# File app/models/proposal.rb, line 99 def has_files? attachments.count > 0 end
Indica si la propuesta tiene foto
# File app/models/proposal.rb, line 93 def has_image? image.present? end
# File app/models/proposal.rb, line 76 def image=(img) self.build_proposal_data unless self.proposal_data self.proposal_data.image = img end
# File app/models/proposal.rb, line 71 def image_cache=(img) self.build_proposal_data unless self.proposal_data self.proposal_data.image_cache = img end
# File app/models/proposal.rb, line 128 def notify_department @notify_department end
Si el usuario deja la URL con el valor por defecto, se quita porque no es una URL vĂ¡lida
# File app/models/proposal.rb, line 123 def nullify_url_if_necessary self.url = nil if self.url.eql?("http://") return true end
Cuerpo de la propuesta, quitando el separador de la entradilla
# File app/models/proposal.rb, line 88 def pretty_body body ? body.sub(/<p.*>###<.*\/p>/, '') : "" end
# File app/models/proposal.rb, line 81 def remove_image=(val) if val.to_i == 1 self.proposal_data.remove_image = true end end
Copia el nombre e email del usuario en la propuesta. Ya no es necesario. Se llama desde before_validation
# File app/models/proposal.rb, line 113 def set_name_and_email if self.user self.name = self.user.public_name self.email = self.user.email self.url = self.user.url end end
# File app/models/proposal.rb, line 132 def to_yaml( opts = {} ) if self.image.present? FileUtils.cp(self.image.path, File.join(RAILS_ROOT, 'data', 'fotos_propuestas_gov')) end YAML.quick_emit( self.id, opts ) { |out| out.map( taguri, to_yaml_style ) { |map| atr = @attributes.dup atr["area_tag_name"] = self.area.present? ? self.area.tag_name_es : '' atr["filename4photo"] = self.image.present? ? File.basename(self.image.path) : '' map.add("attributes", atr) } } end