Ruby on rails 公共活动删除
我在我的rails应用程序上为guidelines模型进行了公共_活动。但是删除一条指导原则会有问题。更新和创建指导原则很好 错误是Ruby on rails 公共活动删除,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我在我的rails应用程序上为guidelines模型进行了公共_活动。但是删除一条指导原则会有问题。更新和创建指导原则很好 错误是 ActiveRecord::RecordNotSaved (You cannot call create unless the parent is saved): app/controllers/guidelines_controller.rb:228:in `destroy' 指南\u controller.rb def destroy @guid
ActiveRecord::RecordNotSaved (You cannot call create unless the parent is saved):
app/controllers/guidelines_controller.rb:228:in `destroy'
指南\u 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
查看公共活动/guideline/\u destroy.html.erb
deleted a guideline
<% if activity.trackable %>
<%= link_to activity.trackable.title, activity.trackable %>
<% else %>
which can no longer be viewed
<% end %>
rails日志说
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
也许您可以尝试在关联中设置:autosave=>true。例如:
class User < ActiveRecord::Base # or wherever location the guidelines association is being set
has_many :guidelines, :autosave => true
...
end
谢谢-我可以把它添加到users.rb有很多:指南,:autosave=>true,但这没有任何区别,抱歉,回到你以前的建议。它确实阻止了这个错误消息的出现,但是“删除指南”并没有添加到我的可跟踪活动反馈中。你有没有找到解决方法?最后,我将@guideline.create_活动:destroy,所有者:current_用户移动到@guideline.destroy之前,使其正常工作。我不喜欢这种情况,以防破坏实际上没有通过。我也有这个问题,你解决了吗?比如@jameswilliamiii,我不喜欢在交易前调用create_活动。奇怪的是,这里似乎有用: