0

I know there are alot of questions on this, but after looking at about a dozen or so none of them appear to be the same problem. I have an "Action" model that I am just simply trying to edit and update. (fyi, this isn't a nested form, I'm not using devise, and this isn't an activeadmin problem...like virtually all other questions about this topic are). I'm getting

error:

unpermitted parameters: utf8, _method, authenticity_token when I do this.

Action params in Actions_controller:

def action_params
    params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why,   :reviewer_id, :reviewed, :spam, :lead)
end

IF I change it to:

    params.require(:action).permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why,   :reviewer_id, :reviewed, :spam, :lead)
end

than I get the below error (and I can't find any solution for this):

undefined method `permit' for "update":String

Actions Controller:

def edit
    @action = Action.find(params[:id])
    @actiontypes = Actiontype.all
    @categories = Category.all
    @lead_categories = @categories.where(lead: true)
    @user = current_user
    @reviewer = User.find(@action.reviewer_id) if @action.reviewed?
end

def update
  @action = Action.find(params[:id])
    if @action.update!(action_params)
      binding.pry
      flash[:success] = "Loop closed!"
      redirect_to '/closingloop/actions?reviewed=false'
    else
      flash[:danger] = "Something Went Wrong! The loop was not closed!"
      render :edit
    end 
end

def action_params
    params.permit(:id, :call_answered, :is_customer, :category_id, :actiontype_id, :why,   :reviewer_id, :reviewed, :spam, :lead)
end

View:

 <%= form_for [:closingloop, @action] do |f| %>
        <%= f.hidden_field :reviewer_id, :value => @user.id %>
        <%= f.hidden_field :reviewed, :value => true %>
        <table width="70%" align="center" class="table table-responsive">
            <tr>
                <th>Tracking Number</th>
                <td><%= @action.company.tracking_phone_number %></td>
            </tr>
            <tr>
                <th>Target Number</th>
                <td><%= @action.company.phonenumber %></td>
            </tr>
            <tr>
                <th>Opportunity Name</th>
                <td><%= @action.opportunity_name %></td>
            </tr>
            <tr>
                <th>Opportunity Address</th>
                <td><%= @action.customer_address %></td>
            </tr>
            <tr>
                <th>Opportunity Phone</th>
                <td><%= @action.caller_phone_number %></td>
            </tr>
            <tr>
                <th>Call Recording</th>
                <td><%= audio_tag(@action.call_recording_link, controls: true) %></td>
            </tr>
            <tr>
                <th>Duration</th>
                <td><%= @action.duration %></td>
            </tr>
            <tr>
                <th>Call Status</th>
                <td><%= @action.call_status %></td>
            </tr>
            <tr>
                <th>Date & Time</th>
                <td><%= @action.created_at.to_formatted_s(:long) %></td>
            </tr>
            <% if @action.reviewed? %>
                <tr id="row_reviewed_by">
                    <th>Reviewed By</th>
                    <td><%= @reviewer.first_name %> <%= @reviewer.last_name %></td>
                </tr>
            <% end %>
            <tr><td colspan="2">&nbsp;</td></tr>
                    <tr id="q_call_answered">
                        <th>Call Answered?</th>
                        <td>
                            <div class="radio-toolbar">
                                <%= f.radio_button :call_answered, true, class: 'call_answered_true' %>
                                <%= f.label :call_answered, "Yes" %>
                                <%= f.radio_button :call_answered, false, class: 'call_answered_false' %>
                                <%= f.label :call_answered, "No" %>
                            </div>
                        </td>
                    </tr>
                    <tr id="why_not_answered" style="display:none;">
                        <th>Why wasn't it answered?</th>
                        <td>
                            <%= f.select :why, options_for_select([["No Answer", "N"], ["Abandoned", "A"], ["After Business Hours", "H"]], @action.why), { include_blank: true } %>
                        </td>
                    </tr>
                    <tr id="q_opportunity" style="display:none;">
                        <th>Was it a opportunity?</th>
                        <td>
                            <div class="radio-toolbar">
                                <%= f.radio_button :is_customer, true, class: 'opportunity_true' %>
                                <%= f.label :is_customer, "Yes" %>
                                <%= f.radio_button :is_customer, false, class: 'opportunity_false' %>
                                <%= f.label :is_customer, "No" %>
                            </div>
                        </td>
                    </tr>
                    <tr id="opportunity_type" style="display:none;">
                        <th>Opportunity Type</th>
                        <td>
                            <%= f.select :actiontype_id, options_from_collection_for_select(@actiontypes, 'id', 'action_type', @action.actiontype_id), { include_blank: true } %>
                        </td>
                    </tr>
                    <tr id="reason_for_call" style="display:none;">
                        <th>Reason for Call</th>
                        <td><%= f.select :category_id, options_from_collection_for_select(@categories, 'id', 'reason', @action.category_id), { include_blank: true }  %></td>
                    </tr>


                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="submit" value="Save" id="save" class="btn btn-success" /></td>
                    </tr>
                  </table>
<% end %>
Steve Q
  • 395
  • 5
  • 28

1 Answers1

0

The main problem here is that if you have model named 'action', your params by default will be named in the same way, which collides with ActionController default params. The simplest solution is, I guess, renaming your model.

Marek Lipka
  • 50,622
  • 7
  • 87
  • 91