强参数 不允许的参数



我知道有很多关于这个问题的问题,但是在看了大约十几个之后,似乎没有一个是同一个问题。我有一个"行动"模型,我只是简单地尝试编辑和更新。(仅供参考,这不是嵌套表单,我没有使用 devise,这不是活动管理员问题......就像几乎所有关于这个主题的其他问题一样)。我得到了

错误:

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

Actions_controller中的动作参数:

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

如果我将其更改为:

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

比我得到以下错误(我找不到任何解决方案):

undefined method `permit' for "update":String

操作控制器:

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

视图:

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

这里的主要问题是,如果你有一个名为"action"的模型,默认情况下你的参数将以相同的方式命名,这与ActionController默认参数发生冲突。我想最简单的解决方案是重命名您的模型。

最新更新