Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 不存储值的模型_Ruby On Rails_Ruby On Rails 4_Model View Controller_Database Design - Fatal编程技术网

Ruby on rails 不存储值的模型

Ruby on rails 不存储值的模型,ruby-on-rails,ruby-on-rails-4,model-view-controller,database-design,Ruby On Rails,Ruby On Rails 4,Model View Controller,Database Design,通过引用,我将具有多对多关系的值存储在Participatentance、TeamAttention表中。该表包含参与者表和事件表的引用 我正在使用Participatentance和TeamAttention的索引页来存储值 路由文件: Rails.application.routes.draw do resources :team_results do collection do put :result end end resources :participant_r

通过引用,我将具有多对多关系的值存储在Participatentance、TeamAttention表中。该表包含参与者表和事件表的引用

我正在使用Participatentance和TeamAttention的索引页来存储值

路由文件:

Rails.application.routes.draw do
 resources :team_results do
   collection do
    put :result
   end
 end
resources :participant_results do
  collection do
   put :result
  end
end
resources :team_attendances do
  collection do
   put :attendance
  end
end

resources :participant_attendances do
  collection do
      put :attendance
  end
end
resources :groupinfos
resources :events
resources :participants
get 'results/index'
get 'attendance/index'
root "participants#index"
end
在设置参与者、团队、结果和参与者、事件之间的关系之前。考勤模块是自动存储值的,但现在它并没有像预期的那样存储值

event.rb:

class Event < ActiveRecord::Base

has_many :selections
has_many :participants, through: :selections

has_many :groupevents
has_many :groupinfos, through: :groupevents

has_many :participant_attendances
has_many :participants, through: :participant_attendances

has_many :participant_results
has_many :participants, through: :participant_results

has_many :team_attendances
has_many :groupinfos, through: :team_attendances

has_many :team_results
has_many :groupinfos, through: :team_results

validates :name, presence: true
end

有什么问题吗?

只有在我第一次重定向表单提交后刷新页面时,表单才起作用。我发现提交按钮并没有向控制器提交值

但在刷新页面后,它工作正常


我在此表单提交中禁用了
turbolinks
,它成功了。

实际尝试存储值的代码在哪里?您是如何确定它不起作用的?使用rails db命令,然后从参与者的出席人数中选择*上传索引页面的代码,这是检索,而不是创建/更新。我们需要看看你是如何创建记录的,以找出为什么它没有被存储。updated my post@RichardAE
class Participant < ActiveRecord::Base

has_many :selections
has_many :events, through: :selections

has_many :groupdetails
has_many :groupinfos, through: :groupdetails

has_many :participant_attendances
has_many :events, through: :participant_attendances

has_many :participant_results
has_many :events, through: :participant_results


validates :name, presence: true
validates :email,:email => true
validates :phone,presence: true,
                 numericality: true,
                 length: { :minimum => 10, :maximum => 10 }
validates :college, presence: true

def full_info
    "#{name}, Participant ID: #{id} "
end
end
class ParticipantAttendance < ActiveRecord::Base
 belongs_to :participant
 belongs_to :event
end
<p id="notice"><%= notice %></p>
<h1>Listing Participant Attendances</h1>
<%= form_tag attendance_participant_attendances_path, method: :put do %>
Round 1
<%= radio_button_tag "round", 1 %>|
Round 2
<%= radio_button_tag "round", 2 %>| 
Round 3
<%= radio_button_tag "round", 3 %>|
Round 4
<%= radio_button_tag "round", 4 %>|
Round 5
<%= radio_button_tag "round", 5 %><br><br>
Present : 
<%= radio_button_tag "mark_present", "present" %>|
Absent  :
<%= radio_button_tag "mark_present", "absent" %><br><br>
<%= submit_tag "Mark Attendance" %>  
<table>
<thead>
<tr>
  <th></th>
  <th>Participant</th>
  <th>Events</th>
  <th>Round</th>
  <th>Status</th> 
  <th colspan="5"></th>
</tr>
</thead>
<tbody>
<% @participant_attendances.each do |participant_attendance| %>
  <tr>
    <td><%= check_box_tag "p_ids[]", participant_attendance.id %></td>      
    <td><%= participant_attendance.participant.name %></td>
    <td><%= participant_attendance.event.name %></td>
    <td><%= participant_attendance.round %></td>
    <td><%= participant_attendance.status %></td>  
    <td><%= link_to 'Show', participant_attendance %></td>
    <td><%= link_to 'Edit', edit_participant_attendance_path(participant_attendance) %></td>
    <td><%= link_to 'Destroy', participant_attendance, method: :delete, data: { confirm: 'Are you sure?' } %></td>
  </tr>
<% end %>
</tbody>
</table>
<% end %>
def attendance
params[:p_ids]
if params[:mark_present]=="present"
  ParticipantAttendance.where(id: params[:p_ids]).update_all(status: 'Present', round: params[:round])
else
  ParticipantAttendance.where(id: params[:p_ids]).update_all(status: 'Absent', round: params[:round])
end  

redirect_to participant_attendances_url
end