积极的管理员强烈的成员行动准备

时间:2017-05-22 15:59:52

标签: activeadmin

我有一个有效的管理员成员操作,其定义如下:

member_action :mark_as_packed, method: [:get, :post] do
    @parcel = Parcel.find(params[:id])
    if request.post?
      @parcel.shipping_fees = permitted_params[:shipping_fees]
      @parcel.status = 'PACKED'
      if @parcel.save
        redirect_to admin_parcel_path(@parcel), notice: "parcel is marked as packed and ready for payment"
      end
    end
  end

根据文档,这会在app/views/admin/parcel/mark_as_packed.html.erb

下呈现模板

该模板如下:

<%= form_for  [:admin, @parcel] , :url  => mark_as_packed_admin_parcel_path,:method => :post do |f| %>
  <% if @parcel.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@parcel.errors.count, "error") %> prohibited this parcel from being saved:</h2>
      <ul>
        <% @parcel.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  <%= f.label :shipping_fees, "shipping fee" %>
  <%= f.text_field :shipping_fees %> 
  <%= f.submit "Submit", :disable_with => 'Submiting...' %>
<% end %>

当我提交表格时,它显示如下:

     {"utf8"=>"✓",
"authenticity_token"=>"BcAqVkSUwVS",
"parcel"=>{"shipping_fees"=>"123.0"}, 
"commit"=>"Submit", 
"id"=>"12"}

请注意shipping_fees嵌套在parcel内,这意味着我必须修改上面的代码,看起来像这样

  @parcel.shipping_fees = permitted_params[:parcel][:shipping_fees]

这不是文件说的: member-actions

所以如何摆脱嵌套参数?

0 个答案:

没有答案