私は現在、週単位の記入フォームを持っています。どのように私は同じページに別のタイムエントリフォームを持つことができますか?これらの2つの書式を別々の記録として別々に提出する必要があります。どんな助けもありがとう。ここでレール上の同じページにフォームタグ付きの2つの提出書類
は私のコードです: -
show_weeks.html.erb
<div class="table-responisve>
<% if @dates != nil %>
<table class="table-bordered">
<thead>
<tr>
<% @dates.each do |date| %>
<th><%=date.to_s+","+date.strftime("%A").to_s %> </th>
<% end %>
</thead>
<tbody>
<tr>
<% @dates.each do |date| %>
<% if @time_entry %>
<td><%= text_field_tag "#{date}", @time_entry.hour_per_day["#{date}"], class: "dates" %></td>
<% else %>
<%if date < Date.today %>
<td> <%= text_field_tag "#{date}", "", class: "dates" %> </td>
<%else %>
<td><%= text_field_tag "#{date}", "", class: "dates" if date == Date.today && Time.now.strftime("%H").to_i >= 10 %> </td>
<% end %>
<% end %>
<% end %>
</tr>
<tr>
<% if @time_entry %>
<td colspan="2"> Please Enter your Comment </td>
<td colspan="5">
<% @time_entry.comments.each do |c| %>
<p><%= text_field_tag "Comment", c.message %> </p>
<% end %>
</td>
<%else%>
<td colspan="2"> Please Enter your Comment </td>
<td colspan="5"><%= text_field_tag "Comment", "" %>
</td>
<%end%>
</tr>
</tbody>
</table>
</div>
<button type="button" class="btn btn-primary"
id="save_entries">Submit</button>
<%= form_tag save_time_entries_path, method: 'post',
id:"save_time_entries" do %>
<%= hidden_field_tag "start_date", @dates.first%>
<%= hidden_field_tag "end_date", @dates.last%>
<%= hidden_field_tag "total_hours", "" %>
<%= hidden_field_tag "project_id", @project.id %>
<%= hidden_field_tag "time_entry", "" %>
<%= hidden_field_tag "message", "" %>
<% if @time_entry%>
<%= hidden_field_tag "time_entry_detail_id", @time_entry.id %>
<% end %>
<% end %>
<script>
$("#save_entries").click(function(){
var time_entry = []
var hours = 0;
var message = document.getElementById("Comment").value;
$('.dates').each(function() {
hours += Number($(this).val());
if ($(this).val() == 0)
{
time_entry.push($(this).attr('name'),0)
}else{
time_entry.push($(this).attr('name'),$(this).val())
}
});
if (hours > 60) {
alert("Total Hours Should be equal to 60");
return false;
}
else {
$("#message").val(message);
$("#time_entry").val(time_entry);
$("#total_hours").val(hours);
$("#save_time_entries").submit();
}
})
</script>
<%end%>
ここでは、合計の時間を計算しています。だから私はform_tagを使ってこれを行う必要があります。フォームタグを使ってこれを行う方法については、 –
https://apidock.com/rails/ActionView/Helpers/FormTagHelper/form_tag ですが、概念的には自分でフォームタグを書くようなものですが、それは誤って入力することを防ぐものです –
この文書は既にチェックされています。それほど役に立たない。あなたのプロンプトのためにありがとう –