如何从rails中的index#action设置属性?

问题描述 投票:1回答:1

project_site模型具有一个属性submission_status。我想从index#action那里设置相应状态的状态。我想在提交按钮上单击每一行以将相应的submission_status更改为true。如何在Rails 5中做到这一点?

index.html.erb

 <table>
      <thead>
        <tr>
          <th>Uploaded Date</th>
          <th>Attendance File</th>
          <th>Submit Attendance</th>

        </tr>
      </thead>
      <tbody>
        <% @project_sites.each do |project_site| %>
          <tr>
            <td><%= project_site.created_at.strftime('%d-%m-%Y') %></td>
            <td><%= link_to "View Attendance", project_site.attendance.url, :class => "fi-page-export-csv" %></td>

            <td>
              <%= form_for ProjectSite.new do |f| %>
                      <%#f.hidden_field :project_site_id, value: project_site.id%>
                      <%=f.hidden_field :submission_status, value: true%>

                    <div>
                      <%= f.submit 'Submit', :class => 'button primary small float-right' %>
                    </div>

              <% end %>
          </tr>
        <% end %>
      </tbody>
    </table>
ruby-on-rails ruby-on-rails-5
1个回答
0
投票
You have to pass the id of project_site for which you want to update the submission_status and on the controller updates the same project_site(id pass as hidden field), for this you need write **ajax** call
<table>
      <thead>
        <tr>
          <th>Uploaded Date</th>
          <th>Attendance File</th>
          <th>Submit Attendance</th>

        </tr>
      </thead>
      <tbody>
        <% @project_sites.each do |project_site| %>
          <tr>
            <td><%= project_site.created_at.strftime('%d-%m-%Y') %></td>
            <td><%= link_to "View Attendance", project_site.attendance.url, :class => "fi-page-export-csv" %></td>

            <td>
              <%= form_for ProjectSite.new do |f| %>
                      <%#f.hidden_field :project_site_id, value: project_site.id%>
                      <%=f.hidden_field :submission_status, value: true%>
                       <%= f.hidden_field :project_site_id, project_site.id%>

                    <div>
                      <%= f.submit 'Submit', :class => 'button primary small float-right' %>
                    </div>

              <% end %>
          </tr>
        <% end %>
      </tbody>
    </table>
© www.soinside.com 2019 - 2024. All rights reserved.