我有我的rails應用程序的指導模型public_activity工作。但刪除指南存在問題。更新和創建準則是好的。Public_activity刪除
錯誤說
ActiveRecord::RecordNotSaved (You cannot call create unless the parent is saved):
app/controllers/guidelines_controller.rb:228:in `destroy'
guidelines_controller.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
guideline.rb
include PublicActivity::Common
視圖public_activity /準則/ _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
你有沒有想過在這方面的解決方法?我最終通過在'@ guideline.destroy'之前移動'@guideline.create_activity:destroy,owner:current_user'來完成它的工作。如果摧毀實際上沒有通過,我不是這個迷。 – jameswilliamiii 2013-08-20 00:29:52
我也有這個問題,你有沒有設法解決它?像@ jameswilliamiii我不喜歡在交易之前調用create_activity – 2013-09-23 08:44:52
很奇怪,這裏似乎工作:http://railscasts.com/episodes/406-public-activity?autoplay=true – unmultimedio 2017-06-16 17:47:24