1

I have an active admin member action that is defined as follows:

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

as per documentation this renders a template under app/views/admin/parcel/mark_as_packed.html.erb

That template looks like:

<%= 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 %>

when I submit the form, it shows params as follows:

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

notice that shipping_fees is nested inside parcel which means that I have to modify the code above to look like this

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

this is not the documentation says: member-actions

so how do I get rid of the nested params ?

Ayed
  • 373
  • 5
  • 17

0 Answers0