Public_activity删除

时间:2013-03-08 00:30:45

标签: ruby-on-rails ruby-on-rails-3

我有一个public_activity正在我的rails应用程序上为指南模型工作。但删除指南存在问题。更新和创建指南很好。

错误说

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 / 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 %>

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

1 个答案:

答案 0 :(得分:0)

也许您可以尝试在关联中设置:autosave => true。例如:

class User < ActiveRecord::Base  # or wherever location the guidelines association is being set
  has_many :guidelines, :autosave => true
 ...
end