在另一个控制器的索引处显示一个控制器的验证形式

时间:2018-08-08 13:03:26

标签: ruby-on-rails ruby haml simple-form simple-form-for

我想实现包括无关控制器的形式到这样的另一个索引页:

enter image description here

我在控制器request_commissioner的索引动作中包含了控制器project_request的形式

有一个问题,当我在没有选定用户的情况下提交创建操作时,它会将我重定向到显示验证的路径/request_commissioners

enter image description here

有什么办法可以在项目请求的索引页上显示验证?

app/controller/project_request_controller

...
  def index
    authorize ProjectRequest

    project_requests = ProjectRequest.all
    @project_requests = smart_listing_create(:project_requests,
                                             project_requests,
                                             partial: "project_requests/list")

    # form_for request_commissioner
    @request_commissioner = RequestCommissioner.new
  end
...

app/views/project_requests/index.html.haml

.page-header
  %h1
    = t ProjectRequest.model_name.human.pluralize.titleize

= smart_listing_controls_for(:project_requests,
                             class: 'form-inline text-right') do  

= smart_listing_render(:project_requests)

app/views/project_requests/_list.html.haml

- smart_listing.collection.each do |dt|
  %tr
    %td= dt.name
    %td= dt.call_call_type.name
    %td= dt.resources
    %td= dt.pi_login
    %td= dt.pi_name
    %td
      - dt.request_commissioners.each do |com|
        %input{ type: "text", value: "#{com.ldapuser.login} - #{com.ldapuser.name} #{com.ldapuser.surname}", disabled: true }

      = simple_form_for(@request_commissioner) do |o|
        = o.error_notification
        .form-inputs
          = o.association :ldapuser,
            prompt: "Select an LDAP user",
            label_method: ->(user) { "#{user.login} - " + "#{user.name} #{user.surname}" },
            include_blank: false,
            collection: dt.possible_evaluators,
            value_method: :login,
            label: false

          = o.input :request_id, input_html: { value: dt.id }, value: dt.id.to_i, as: :hidden
          = o.input :audit_comment, input_html: {value: "Adding evaluator to request id: #{dt.id.to_s}"}, as: :hidden
          .form-actions
            = o.button :submit

app/controllers/request_commissioner_controller.rb

  def create
    authorize RequestCommissioner

    @request_commissioner = RequestCommissioner.new(request_commissioner_params)

    respond_to do |format|
      if @request_commissioner.save
        format.html { redirect_back fallback_location: { action: "show" }, notice: 'Request Commissioner  was successfully created.' }
        format.json { render :show, status: :created, location: @request_commissioner }
      else
        format.html { render :new }
        format.json { render json: @request_commissioner.errors, status: :unprocessable_entity }
      end
    end
  end

我想知道,是否有一种方法可以显示另一个控制器的形式,而不是显示的索引。以及如何在索引页面上显示验证而无需重定向。

我也想保留request_commissioners CRUD操作的路径,这些路径可以通过路由resource :request_commissioners

使用

编辑

project_requests#index - Create RequestCommisioner log - success

Started POST "/request_commissioners" for 10.0.1.29 at 2018-08-09 09:39:05 +0200
Processing by RequestCommissionersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"QxQx58PHxNJNIanHMBphDLMzaWoq7NNWpce1e/6/wKKARhg9kxA5W9
5EAUt1kQAMbCDWxnM9FKseI7Wei8cumw==", "request_commissioner"=>{"login"=>"111newone", "request_id"=>"33", "
audit_comment"=>"Adding evaluator to request id: 33"}, "commit"=>"Create Request commissioner"}
   (0.1ms)  BEGIN
  ...
  SQL (0.2ms)  INSERT INTO `request_commissioners` (`request_id`, `login`, `created_at`, `updated_at`) VA
LUES (33, '111newone', '2018-08-09 07:39:05', '2018-08-09 07:39:05')
  AuditChangesExtension Load (0.4ms)  SELECT  `audits`.* FROM `audits` WHERE `audits`.`auditable_id` = 25
 AND `audits`.`auditable_type` = 'RequestCommissioner' ORDER BY `audits`.`version` DESC LIMIT 1
  SQL (0.3ms)  INSERT INTO `audits` (`auditable_id`, `auditable_type`, `associated_id`, `associated_type`
, `username`, `action`, `audited_changes`, `version`, `comment`, `remote_address`, `request_uuid`, `creat
ed_at`) VALUES (25, 'RequestCommissioner', 4550, 'Ldapuser', 'J K|admin|, 'create'
, '---\nrequest_id: 33\nlogin: 111newone\n', 1, 'Adding evaluator to request id: 33','3d5
29c2b-e11d-45ee-9c8c-31e6416fc2e5', '2018-08-09 07:39:05')
   (1.1ms)  COMMIT
 ...
Redirected to http://10.5.19.19:3000/project_requests
Completed 302 Found in 23ms (ActiveRecord: 3.8ms)

project_requests#index - Create RequestCommisioner log - error (validations render)

Started POST "/request_commissioners" for 10.0.131.29 at 2018-08-09 09:41:49 +0200
Processing by RequestCommissionersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"EweXAJvv/P0ZnTUVKkO4XLMQnrtfm0tk5B4HHqMY5CvQVb7ayzgBdIr4nZlvyNlcbAMhFwZKjJlf+gf71mAKEg==", "request_commissioner"=>{"login"=>"", "request_id"=>"36", "audit_comment"=>"Adding evaluator to request id: 36"}, "commit"=>"Create Request commissioner"}
   (0.1ms)  BEGIN
  ...
   (0.1ms)  ROLLBACK
  Rendering request_commissioners/new.html.haml within layouts/application
  Ldapuser Load       (0.2ms)  SELECT `evaluator_committees`.`login` FROM `evaluator_committees`
  ...
  Rendered request_commissioners/_form.html.haml (49.1ms)
  Rendered request_commissioners/new.html.haml within layouts/application (53.7ms)
  Rendered application/_audit_destroy_modal.haml (16.5ms)
Completed 200 OK in 717ms (Views: 702.3ms | ActiveRecord: 5.2ms)

request_commissioners#new - Create RequestCommisioner log - success

Started POST "/request_commissioners" for 10.0.131.29 at 2018-08-09 09:43:26 +0200
Processing by RequestCommissionersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"p0sUX0kXRjzghTsv1yodYqTVNV0s3wovC2q16WikPetkGT2FGcC7tXPgk6OSoXxie8aK8XUOzdKwjrUMHdzT0g==", "request_commissioner"=>{"login"=>"111newone", "request_id"=>"603", "audit_comment"=>"test"}, "commit"=>"Create Request commissioner"}
  User Load (0.7ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
   (0.1ms)  BEGIN
  SQL (0.4ms)  INSERT INTO `request_commissioners` (`request_id`, `login`, `created_at`, `updated_at`) VALUES (603, '111newone', '2018-08-09 07:43:26', '2018-08-09 07:43:26')
  AuditChangesExtension Load (0.4ms)  SELECT  `audits`.* FROM `audits` WHERE `audits`.`auditable_id` = 26 AND `audits`.`auditable_type` = 'RequestCommissioner' ORDER BY `audits`.`version` DESC LIMIT 1
  SQL (0.3ms)  INSERT INTO `audits` (`auditable_id`, `auditable_type`, `associated_id`, `associated_type`, `username`, `action`, `audited_changes`, `version`, `comment`, `remote_address`, `request_uuid`, `created_at`) VALUES (26, 'RequestCommissioner', 4550, 'Ldapuser', ' |admin|', 'create', '---\nrequest_id: 603\nlogin: 111newone\n', 1, 'test', '10.0.131.29', '55bfd638-617d-4186-943d-cfe3b9f8a082', '2018-08-09 07:43:26')
   (8.4ms)  COMMIT
Redirected to http://10.5.19.19:3000/request_commissioners/new
Completed 302 Found in 31ms (ActiveRecord: 12.0ms)

request_commissioners#new - Create RequestCommisioner log - error - trigger validations

Started POST "/request_commissioners" for 10.0.131.29 at 2018-08-09 09:44:19 +0200
Processing by RequestCommissionersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"LvlstKPw1qW13miIM5zqQmBfaYQIYyB3yYUmmc2ABzXtq0Vu8ycrLCa7wAR2F4tCv0zWKFGy54pyYSZ8uPjpDA==", "request_commissioner"=>{"login"=>"", "request_id"=>"603", "audit_comment"=>""}, "commit"=>"Create Request commissioner"}
   (0.2ms)  BEGIN
   ...
  Ldapuser Load (0.2ms)  SELECT  `ldapusers`.* FROM `ldapusers` WHERE `ldapusers`.`login` = '' LIMIT 1
   (0.1ms)  ROLLBACK
  Rendering request_commissioners/new.html.haml within layouts/application
  ProjectRequest Load (3.9ms)  SELECT `project_requests`.* FROM `project_requests` ORDER BY name ASC
  Rendered request_commissioners/_form.html.haml (45.0ms)
  Rendered request_commissioners/new.html.haml within layouts/application (48.8ms)
  Rendered application/_audit_destroy_modal.haml (16.4ms)
Completed 200 OK in 713ms (Views: 699.6ms | ActiveRecord: 5.8ms)

0 个答案:

没有答案