Class: Partner
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Partner
- Extended by:
- FriendlyId
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- app/models/partner.rb
Defined Under Namespace
Classes: Translation
Class Method Summary collapse
-
.reorder_positions(ids = nil) ⇒ Object
Refaz a ordenação dos uploads.
Instance Method Summary collapse
-
#to_jq_upload ⇒ Object
include I18n::Backend::Fallbacks include I18n::Backend::Simple.
- #translations_attributes=(attributes) ⇒ Object
Class Method Details
.reorder_positions(ids = nil) ⇒ Object
Refaz a ordenação dos uploads
69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/partner.rb', line 69 def self.reorder_positions(ids = nil) [] if ids.blank? counter = 1 ActiveRecord::Base.establish_connection ids.each do |id| ActiveRecord::Base.connection.execute("UPDATE partners SET position=#{counter} WHERE id='#{id}';\n") counter += 1 end return true end |
Instance Method Details
#to_jq_upload ⇒ Object
include I18n::Backend::Fallbacks include I18n::Backend::Simple
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/models/partner.rb', line 43 def to_jq_upload { "id" => read_attribute(:id), "name" => read_attribute(:name) || read_attribute(:partner_file_name), "content_type" => read_attribute(:partner_content_type), "size" => read_attribute(:partner_file_size), "updated_at" => read_attribute(:updated_at), "created_at" => read_attribute(:created_at), "images" => { "original" => partner.url, "thumb" => partner.url(:thumb ), }, "url" => partner.url(:original), "thumb" => partner.url(:thumb), "edit_url" => edit_admin_partner_path(self), "delete_url" => admin_partner_path(self), "delete_type" => "DELETE", "i18n" => { "size" => number_to_human_size(read_attribute(:partner_file_size)), "updated_at" => I18n.l(read_attribute(:updated_at), format: :long), "created_at" => I18n.l(read_attribute(:created_at), format: :long), } } end |
#translations_attributes=(attributes) ⇒ Object
30 31 32 33 34 35 |
# File 'app/models/partner.rb', line 30 def translations_attributes=(attributes) new_translations = attributes.values.reduce({}) do |new_values, translation| new_values.merge! translation.delete("locale") => translation end set_translations new_translations end |