Rails ActionController :: ParameterMissing错误

时间:2016-03-11 16:27:39

标签: ruby-on-rails

我想独立于表单本身更新表单上的状态字段。换句话说,用户可以通过弹出窗口更改状态。一旦他们点击提交,窗体将关闭。我有类似的情况,但不能在这里复制它。

我正在调用弹出窗口。

   <%= link_to( '<button>Change the status</button>'.html_safe,
                           "/complaints/edit_status",
                           'data-popup' => true,
                           remote: true,
                           :class => "button_class",
                           :onclick=>"window.open(this.href,'change the status', 'height=500, width=500');
                                         return false;"
                  ) %><br>

我的适用路线是

get 'complaints/edit_status' => 'complaints#edit_status'
  post 'complaints/edit_status' => 'complaints#edit_status'

我的控制器中的edit_status方法是

  def edit_status
  @complaint = Complaint.find($current_record_id)
   respond_to do |format|
   if @complaint.update_attributes(complaint_params)
         format.html { render :text => '<script type="text/javascript">
                                         alert("The status was updated");
                                          window.close();
                                          </script>' }
   else                                                                         # otherwise show a standard message
        format.html { render :text => '<script type="text/javascript">
                                         alert(" There was an error in saving");
                                          window.close();
                                         </script>'
        }
   end
     end
  end

我的edit_status.html.erb只是<%= render 'form_for_status' %>

我的投诉表格是

<%= form_for @complaint, :html => { :class => 'form-horizontal', multipart: true} do |f| %>
  <% if @complaint.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@complaint.errors.count, "error") %> prohibited this complaint from being saved:</h2>

      <ul>
      <% @complaint.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>
          <div class="field" id="refresh_status">
            <%= f.label :status %><br>
            <%= f.select :status, options_for_status, :prompt => 'Select One' %>
          </div>
   <div class="actions">
      <%= f.submit %>
    </div>
<% end %>

我得到的错误是

ActionController::ParameterMissing in ComplaintsController#edit_status
param is missing or the value is empty: complaint

Rails.root: C:/Users/cmendla/RubymineProjects/internal_complaints

Application Trace | Framework Trace | Full Trace
app/controllers/complaints_controller.rb:252:in `complaint_params'
app/controllers/complaints_controller.rb:16:in `block in edit_status'
app/controllers/complaints_controller.rb:14:in `edit_status'

如果我注释了respond_to块,那么表单可以正常工作,但在提交时它不会关闭。

如果我将respond_to留在(没有<% @complaint.errors.full_messages.each do |message| %>,那么表单就会关闭。

如果我有respond_to和<% @complaint.errors.full_messages.each do |message| %>,那么我会收到错误消息。

我的日志显示

Started GET "/complaints/edit_status" for ::1 at 2016-03-11 11:25:54 -0500
Processing by ComplaintsController#edit_status as HTML
  [1m[35mUser Load (1.0ms)[0m  EXEC sp_executesql N'SELECT  [ic].[users].* FROM [ic].[users] WHERE [ic].[users].[id] = @0  ORDER BY [ic].[users].[id] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', N'@0 int', @0 = 1  [["id", 1]]
  [1m[36mComplaint Load (2.0ms)[0m  [1mEXEC sp_executesql N'SELECT  [ic].[complaints].* FROM [ic].[complaints] WHERE [ic].[complaints].[id] = @0  ORDER BY [ic].[complaints].[id] ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY', N'@0 int', @0 = 1[0m  [["id", 1]]
Completed 400 Bad Request in 13ms (ActiveRecord: 3.0ms)

ActionController::ParameterMissing (param is missing or the value is empty: complaint):
  app/controllers/complaints_controller.rb:252:in `complaint_params'
  app/controllers/complaints_controller.rb:16:in `block in edit_status'
  app/controllers/complaints_controller.rb:14:in `edit_status'

0 个答案:

没有答案