mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 12:31:42 +00:00
Soportar campos númericos con decimales
This commit is contained in:
parent
1623ab73de
commit
9b8c09cb00
3 changed files with 40 additions and 0 deletions
31
app/models/metadata_float.rb
Normal file
31
app/models/metadata_float.rb
Normal file
|
@ -0,0 +1,31 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Un campo numérico de punto flotante
|
||||
class MetadataFloat < MetadataTemplate
|
||||
# Nada
|
||||
def default_value
|
||||
super || nil
|
||||
end
|
||||
|
||||
def save
|
||||
return true unless changed?
|
||||
|
||||
self[:value] = value.to_f
|
||||
self[:value] = encrypt(value) if private?
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
# Indicarle al navegador que acepte números decimales
|
||||
#
|
||||
# @return [Float]
|
||||
def step
|
||||
0.05
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def decrypt(value)
|
||||
super(value).to_f
|
||||
end
|
||||
end
|
3
app/views/posts/attribute_ro/_float.haml
Normal file
3
app/views/posts/attribute_ro/_float.haml
Normal file
|
@ -0,0 +1,3 @@
|
|||
%tr{ id: attribute }
|
||||
%th= post_label_t(attribute, post: post)
|
||||
%td{ dir: dir, lang: locale }= metadata.value
|
6
app/views/posts/attributes/_float.haml
Normal file
6
app/views/posts/attributes/_float.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
.form-group
|
||||
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
|
||||
= number_field base, attribute, value: metadata.value, step: metadata.step,
|
||||
**field_options(attribute, metadata)
|
||||
= render 'posts/attribute_feedback',
|
||||
post: post, attribute: attribute, metadata: metadata
|
Loading…
Reference in a new issue