I have a model with a method called date_string. The point of this method is to return a formatted date string when being used in a share view. Here is the view code.
<div class="field control-group">
<div class="control-label">
<%= f.label :business_hour , :date_string %>
</div>
I am expecting the f.label call to function like in this api doc, with :business_hour being the object, and :date_string being the method. However, the only thing that is rendered to the view is the string 'Date string' or 'date_string'.
Any help on getting a view class to call a method, not a property, on a model is greatly appreciated.
Business_Hour code
class BusinessHour < ActiveRecord::Base
attr_accessible :business_hourable_id,
:business_hourable_type,
:close_time, :day, :open_time,
:order , :business_date
belongs_to :business_hourable , :polymorphic => true
def date_string()
if business_date.nil?
return ''
else
return_string = business_date.strftime( '%a %b\ %e , %Y' )
end
end
end
Here is the full partial code(shared/business_hours):
<div class="field control-group">
<div class="control-label funkiness">
<%= F.label :business_hour , :date_string %>
</div>
<div class="controls">
<%= f.select :open_time, available_hours, :include_blank => true %>
</div>
<div class="control-label">
<%= f.label :open_time, 'Close Time' %>
</div>
<div class="controls">
<%= f.select :close_time, available_hours, :include_blank => true %>
</div>
</div>
Here is the pertinent part of the _form <%= form_for (@some_show), html: {class: "form-horizontal pull-left"} do |f| %> ... <%= f.fields_for :business_hours do |operating_time| %> <%= render :partial => 'shared/business_hours', :locals => {:f => operating_time} %> <% end %>
And finally, here is the edit action of the controller
# GET /some_shows/1/edit
def edit
@some_show = SomeShow.find(params[:id])
end