Class: Slider
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Slider
- Extended by:
- FriendlyId
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- app/models/slider.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
77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/slider.rb', line 77 def self.reorder_positions(ids = nil) [] if ids.blank? counter = 1 ActiveRecord::Base.establish_connection ids.each do |id| ActiveRecord::Base.connection.execute("UPDATE sliders 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/slider.rb', line 49 def to_jq_upload { "id" => read_attribute(:id), "name" => read_attribute(:name) || read_attribute(:background_file_name), "content_type" => read_attribute(:background_content_type), "size" => read_attribute(:background_file_size), "updated_at" => read_attribute(:updated_at), "created_at" => read_attribute(:created_at), "images" => { "original" => background.url, "page" => background.url(:page ), "thumb" => background.url(:thumb ), }, "url" => background.url(:original), "page" => background.url(:page), "thumb" => background.url(:thumb), "edit_url" => (self), "delete_url" => (self), "delete_type" => "DELETE", "i18n" => { "size" => number_to_human_size(read_attribute(:background_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
36 37 38 39 40 41 |
# File 'app/models/slider.rb', line 36 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 |