There's not a lot of documentation as to how to use the display_with option in Best In place, but I'm trying to get Best_in_Place to display dates in condensed form, (mm/dd/yyyy). My db (sqlserver) has the dates stored in datetime format, and I use this command to display the field:
<%= best_in_place(@production, :budget_approval_internal, type: :date, :nil => "[Not set]") %>
When clicked the gem works as expected, putting up a calendar control to select the date, and then displaying it in short form. But when I press refresh I get a date that looks like:
2013-12-04 00:00:00 UTC
So I thought I could use the :display_with option to have use a helper that looks like this:
def format_date(my_date)
my_date.strftime('%m/%d/%Y')
end
I put this in the application_helper.rb module and then tried this:
<%= best_in_place(@production, :budget_approval_internal, type: :date, :display_with => :format_date, :nil => "[Not set]") %>
but I get an error in saying:
"can't find helper format_date. Any ideas?
I ran into the same problem and used a small snippet from the pull requests of best_in_place done by zubin.
<%= in_place_edit(@term, :starts_on, display_with: lambda { |dt| ldt(dt) }, html_attrs: {datepicker: "true"}) %>
here the ldt is the method which takes a date object and converts to format of my desire.
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With