Reputation: 8451
I have a scenario where the client wants the value of Null
displayed in the view for a particular field if it is nil. But, if that value is nil I don't actually want to send the value if Null
to the server I still want to treat that field as if it were nil and nothing was sent. Here is what I'm working with:
<%= form.text_field :fee, value: finfolio_fee_presence(@account.fee), class: "finfolio-fields__input", readonly: true %>
def finfolio_fee_presence(value)
value.nil? ? "Null" : value
end
So, this displays the value to the user that the client wants but I don't actually want to send "Null" in this case. How can I treat this as nil and not send this field to the server if it is nil?
Upvotes: 1
Views: 86
Reputation: 11
<%= form.text_field :fee,
value: finfolio_fee_presence(@account.fee),
class: 'finfolio-fields__input',
disabled: @account.fee.nil? %>
Upvotes: 0
Reputation: 33450
What about using the disabled option in case the @account.fee
is nil?, it'll show your text_field and its "tweaked" value, but it won't go within the params:
<%= form.text_field :fee,
value: finfolio_fee_presence(@account.fee),
class: 'finfolio-fields__input',
disabled: @account.fee.nil? %>
Upvotes: 1