こんにちは私はそれをデータベースと比較して存在するかどうかチェックするためにフォームからstart_hourパラメータを要求する必要がありますが、フォームにあるパラメータを再入力するとRuby on Rails DateTimeが必要ですparam
<%= f.datetime_select :start_hour, { :order => [:month, :day, :year, :hour, :minute], :prompt => { :day => 'Dia', :month => 'Mes', :year => 'Ano', :hour => 'Hora', :minute => 'Minuto' } }, {:class => "form-control", :style => "display: inline-block;
width: auto;
vertical-align: middle;"} %>
私はコントローラーでこれをnilとしていますが、どのようにdatetime形式を要求できますか?どうもありがとう。あなたはあなたの強いパラメータのパラメータを設定した場合、ここに私のコントローラ
def create
@start_hour = params[:courtesie][:start_hour]
@lesson_check = Lesson.find_by(start_date: @start_hour)
if @lesson_check.present?
@new_courtesie = Courtesie.new(courtesie_params)
@new_schedule = Schedule.new()
@new_schedule.options = params[:courtesie][:name]
@new_schedule.lesson_id = @lesson_check.id
@new_schedule.user_id = current_user.id
if @new_courtesie.save && @new_schedule.save
flash[:success] = "Cortesia agendada"
redirect_to cortesias_path
end
else
flash[:warning] = @start_hour
redirect_to cortesias_path
end
end
フォームコード
<%= form_for(:courtesie, html: { class: "form-horizontal" }) do |f| %>
<div class="form-group">
<label class="control-label col-md-2" for="sitename"> Nombre cortesia
</label>
<div class="col-md-9">
<%= f.text_field :name, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="sitename"> Fecha cortesia</label>
<div class="col-lg-10">
<%= f.datetime_select :start_hour, { :order => [:month, :day, :year, :hour, :minute], :prompt => { :day => 'Dia', :month => 'Mes', :year => 'Ano', :hour => 'Hora', :minute => 'Minuto' } }, {:class => "form-control", :style => "display: inline-block;
width: auto;
vertical-align: middle;"} %>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="sitename"> Telefono </label>
<div class="col-md-5">
<%= f.number_field :phone, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="sitename"> Email </label>
<div class="col-md-5">
<%= f.text_field :email, class: 'form-control' %>
</div>
</div>
<div class="form-group">
<div class="col-lg-9 col-lg-offset-2">
<%= f.submit "Guardar", class: "btn btn-primary" %>
<button type="reset" class="btn btn-default">Reiniciar</button>
</div>
</div>
<% end %>
@ArunKumarノップ私はどんな終わりも見逃さない、それについてのエラーが出ないよ – mdiaz00147
すみません。私は間違っていた、なぜ私は私のコメントを削除した。決して気にしない –
フォームコードを投稿できますか?修正がありますが、フォームコードを確認する前に共有することはできません。 –