我一直在收到错误消息,说我在尝试销毁Feature
时没有传递ID,但我使用set_feature before_action
执行此操作!
完整错误:
wrong number of arguments (0 for 1)
Extracted source (around line #63):
private
# Use callbacks to share common setup or constraints between actions.
def set_feature(params)
@feature = Feature.find(params[:id])
end
Rails.root: C:/Users/Nick/Amnesia_Rails/Master
Application Trace | Framework Trace | Full Trace
app/controllers/apps/elements/features_controller.rb:63:in `set_feature'
Request
Parameters:
{"_method"=>"delete",
"authenticity_token"=>"0Z/SxhhEO6OA6eiShd+1PZI0DQ9QK1I7G8wqoInz+vM=",
"element_id"=>"3",
"id"=>"5"}
节目观点:
<% @app.elements.each do |element| %>
<tr>
<td><b><%= element.name %></b></td>
<td><b><%= element.description %></b></td>
<td><b><%= link_to "Remove", [@app, element], method: :delete, confirm: "Are you sure?" %></b></td>
</tr>
<% element.features.each do |feature| %>
<tr>
<td><%= feature.name %></td>
<td><%= feature.description %></td>
<td><%= link_to "Delete", [element, feature], method: :delete %></td>
</tr>
<% end %>
<tr>
<td><%= link_to 'Add a Feature', new_element_feature_path(element) %></td>
</tr>
</tr>
<% end %>
破坏和隐私方法:
def destroy
@feature = Feature.find(params[:id])
@feature.destroy
@element = Element.find(params[:element_id])
redirect_to(@element.app)
end
private
# Use callbacks to share common setup or constraints between actions.
def set_feature(params)
@feature = Feature.find(params[:id])
end
任何帮助将不胜感激!我很失落!
答案 0 :(得分:2)
我认为0对于你来说非常清楚。
def set_feature(params)
end
那是错的。 (params)是你的1.如果你没有传递一些东西,那就是0.而你不是。
只需进行你的before_action:
def set_feature
@feature = Feature.find(params[:id])
end
答案 1 :(得分:1)
before_action不会神奇地传递给参数。
我认为您应该能够访问“params”而不将其作为set_feature的参数。