我有 public_activity 在我的 rails 应用程序上为指南模型工作。但是删除指南存在问题。更新和创建指南很好。
错误说
ActiveRecord::RecordNotSaved (You cannot call create unless the parent is saved):
app/controllers/guidelines_controller.rb:228:in `destroy'
指南控制器.rb
def destroy
@guideline = Guideline.find(params[:id])
@guideline.destroy
@guideline.create_activity :destroy, owner: current_user
respond_to do |format|
format.html { redirect_to guidelines_url }
format.json { head :no_content }
end
end
def update
@guideline = Guideline.find(params[:id])
if @guideline.update_attributes(params[:guideline])
@guideline.create_activity :update, owner: current_user
end
def create
@guideline = current_user.guidelines.new(params[:guideline])
if @guideline.save
@guideline.create_activity :create, owner: current_user
end
指南.rb
include PublicActivity::Common
查看 public_activity/guideline/_destroy.html.erb
deleted a guideline
<% if activity.trackable %>
<%= link_to activity.trackable.title, activity.trackable %>
<% else %>
which can no longer be viewed
<% end %>
导轨日志说
Processing by GuidelinesController#destroy as HTML
Parameters: {"authenticity_token"=>"SpdYUFk0Bv1KuVg6oEuDUU4MI3eD6C1nV/3bmd5Xhsg=", "id"=>"9-jannit"}
Guideline Load (0.2ms) SELECT "guidelines".* FROM "guidelines" WHERE "guidelines"."id" = ? LIMIT 1 [["id", "9-jannit"]]
(0.1ms) begin transaction
Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."guideline_id" = 9
SQL (0.7ms) DELETE FROM "guidelines" WHERE "guidelines"."id" = ? [["id", 9]]
SOLR Request (224.9ms) [ path=#<RSolr::Client:0x007f9ebdc5ea50> parameters={data: <?xml version="1.0" encoding="UTF-8"?><delete><id>Guideline 9</id></delete>, headers: {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby}, query: wt=ruby, path: update, uri: http://localhost:8982/solr/update?wt=ruby, open_timeout: , read_timeout: } ]
(3.3ms) commit transaction
(0.1ms) begin transaction
SOLR Request (4.8ms) [ path=#<RSolr::Client:0x007f9ebdc5ea50> parameters={data: <?xml version="1.0" encoding="UTF-8"?><delete><id>Guideline 9</id></delete>, headers: {"Content-Type"=>"text/xml"}, method: post, params: {:wt=>:ruby}, query: wt=ruby, path: update, uri: http://localhost:8982/solr/update?wt=ruby, open_timeout: , read_timeout: } ]
(0.1ms) commit transaction
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 3 LIMIT 1
Completed 422 Unprocessable Entity in 254ms