I have a form which creates the default time of 6.45pm. When a new form is created
_form.html.erb
= f.input :started_at, as: :string, class: 'form-control', input_html: { value: l(@happening.started_at, format: :date_time_picker), class: 'date_time_picker' }, label: "Start at"
but instead of showing 1845 in my happenings controller i want to replace it with the usual_start_time field in my areas table
scheme.rb
create_table "areas", force: :cascade do |t|
t.string "deprecated__default_postcode", limit: 255
t.integer "number_of_runners_needed", default: 100, null: false
t.string "referral_partners_logo_image"
t.integer "address_id"
**t.string "usual_start_time", default: "18:45"**
end
I have tried using
time = DateTime.strptime((Date.today + 1.day).to_s + ' ' + **"#{@area.usual_start_time}"**, '%Y-%m-%d %H:%M')
but it gives me undefined method `usual_start_time' for nil:NilClass
also tried
time = DateTime.strptime((Date.today + 1.day).to_s + ' ' + **"#{@area.happenings.usual_start_time}"**, '%Y-%m-%d %H:%M')
happenings_controller.rb (want to replace "18.45"
def new
@type = params[:type].underscore
time = DateTime.strptime((Date.today + 1.day).to_s + ' ' + **"18:45"**, '%Y-%m-%d %H:%M')
@happening = Happening.new(started_at: time)
end
Aucun commentaire:
Enregistrer un commentaire