我知道这方面有很多问题,但在看了大约十几个之后,似乎没有一个问题出现在同一个问题上。我有一个" Action"我只是简单地尝试编辑和更新的模型。 (fyi,这不是一个嵌套的形式,我不使用设计,这不是一个activeadmin问题......就像关于这个主题的几乎所有其他问题一样)。我得到了
错误:
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"> </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> </td>
<td><input type="submit" value="Save" id="save" class="btn btn-success" /></td>
</tr>
</table>
<% end %>
答案 0 :(得分:0)
这里的主要问题是,如果你有一个名为'action'的模型,默认情况下你的params将以相同的方式命名,它与ActionController
默认参数冲突。我想,最简单的解决方案是重命名模型。