微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在Ruby on Rails 5.2中将其他控制器的视图呈现为模式窗口?

如何解决如何在Ruby on Rails 5.2中将其他控制器的视图呈现为模式窗口?

我的应用程序根据Skills实施了Sumit / Approve / Reject工作流程。当一项技能被拒绝时,它会创建一个通知通知用户应通过模式窗口输入原因。不幸的是,我对前端开发不满意,并且不会显示模式窗口:它不是在页面的html输出生成的。这是我写的代码

1-当按下“拒绝”按钮(在“技能的显示”视图中)时,Skills控制器会创建一个通知,并尝试呈现Notifications控制器(使用@notification变量)的notifications_edit_description_form.html.erb部分。

  def reject
    puts "-------------------------------------------------------"
    puts "------------------ REJECTED ---------------------------"
    puts "-------------------------------------------------------"
    @skill.reject!
    @skill.update_attribute(:status_id,statuses.find { |x| x["code"] == "REJECTED" }.id || 0)
    @notification = Notification.create(playground_id: current_playground,description: t('SkillRejected'),severity_id: options_for('rules_severity').find { |x| x["code"] == "CORRECTION" }.id || 0,status_id: statuses.find { |x| x["code"] == "NEW" }.id || 0,expected_at: Time.Now + 1.day,responsible_id: @skill.parent.parent.reviewer_id,owner_id: current_user.id,created_by: current_login,updated_by: current_login,topic_type: @skill.class.name,topic_id: @skill.id,deputy_id: @skill.parent.parent.responsible_id,organisation_id: @skill.organisation_id,code: @skill.code,name: t('SkillRejected'))
    # Create title and description for current language
    @notification.name_translations.create(field_name: 'name',language: current_language,translation: "#{t('Skill')} #{@skill.code} #{@skill.workflow_state}")
    @notification.description_translations.create(field_name: 'description',translation: "#{format_datetime(Time.Now)} #{current_user.name} :\n> #{t('SkillRejected')}")
    render partial: 'notifications/edit_description_form',data: { toggle: "modal",target: "#editNotificationModal" }
  end

2 -notifications_edit_description_form.html.erb部分为:

<%= form_with model: @notification,html: {id: "edit_description_form"} do |f| %>

  <div class="modal-header">
    <h5 class="modal-title" id="editNotificationModalLabel">
      <% if content_for?(:notificationModalTitle) %>
        <%= yield(:notificationModalTitle) %>
      <% else %>
        <%= t('EditNotification') %>
      <% end %>
    </h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">

    <%= render partial: "shared/error_list",locals: { errors: @notification.errors } %>

    <fieldset>
      <div class="row mat-form-row">
        <div class="mat-form-field col-md-4">
          <%= f.label :notification_severity_id,t('NotificationSeverity'),class: "mat-form-field-label" %>
          <%= f.collection_select :severity_id,options_for('rules_severity'),:id,:name,{},{ class: "mat-input-element" } %>
        </div>
        <div class="mat-form-field col-md-4">
          <label for="notification-issuer" class="mat-form-field-label">
            <%= t('Issuer') %>
          </label>
          <input id="notification-issuer" class="mat-input-element" readonly
            value="<%= @notification.owner.name %>" />
        </div>
        <div class="mat-form-field col-md-4">
          <%= f.label :notification_expected_at,t('NotificationDueDate'),class: "mat-form-field-label" %>
          <%= f.date_field :expected_at,{ class: "mat-input-element" } %>
        </div>
      </div>
      <div class="row mat-form-row">
        <div class="mat-form-field col-md-4">
          <%= render partial: "shared/translated_field_form",locals: {
            f: f,field: "description",fields: :description_translations,translations: @notification.description_translations,isTextarea: true,smallTextarea: true,label: t('Description') } %>
        </div>
      </div>
    </fieldset>
  </div>

  <div class="modal-footer">
    <button type="button" class="mat-stroked-button mat-button-base" data-dismiss="modal">
      <%= t('Cancel') %>
    </button>
    <button class="mat-flat-button mat-button-base mat-primary">
      <%= t('Submit') %>
    </button>
  </div>

<% end %>

3-目标是在“技能的表演”视图中定义的。

<!-- Notification Modal -->
<aside class="modal fade modal-remote" id="editNotificationModal" tabindex="-1" role="dialog" aria-labelledby="editNotificationModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-lg">
    <div class="modal-content"></div>
  </div>
</aside>

4-控制台报告部分已渲染:

  Rendered notifications/_edit_description_form.html.erb (67.1ms)

我想念什么?我的模态去了哪里,以及如何解决这个问题?

非常感谢您的帮助!

解决方法

我发现的解决方案可能不是最佳的,但这是有效的:从“显示”视图中,链接到具有模态目标的新通知路径实际上会在模态窗口中打开通知。

        <%= link_to t('Reject'),new_notification_path(
                                  playground_id: current_playground,description: t("#{this_object.class.name}#{'Rejected'}"),severity_id: options_for('rules_severity').find { |x| x["code"] == "CORRECTION" }.id || 0,status_id: statuses.find { |x| x["code"] == "NEW" }.id || 0,expected_at: Time.now + 1.day,responsible_id: this_object.owner_id,owner_id: current_user.id,created_by: current_login,updated_by: current_login,topic_type: this_object.class.name,topic_id: this_object.id,deputy_id: this_object.parent.responsible_id,organisation_id: this_object.organisation_id,code: this_object.code,name: t("#{this_object.class.name}#{'Rejected'}")
                                    ),title: t('Reject'),data: { 
                                  toggle: "modal",target: "#editNotificationModal" 
                                  },class: "mat-stroked-button mat-button-base mat-primary" %>

当通知模式窗口关闭时,技能展示视图仍然可用。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。