【问题标题】:Duplicating an object's attributes including Paperclip uploaded image Rails 3复制对象的属性,包括回形针上传的图像 Rails 3
【发布时间】:2013-03-18 09:49:31
【问题描述】:

我是 Rails 新手,想弄清楚为什么这不起作用! 我正在尝试复制属于另一个用户的对象,并将其设为我的。一切正常,但有两件事: 1.图像确实信息重复但图像显示为损坏

  1. 用户可以反复复制对象。

我的代码:

class EventsController < ApplicationController    
  def calee
    @event = Event.find(params[:id])
    @image = @event.event_image
    if @event.user_id != current_user.id
      @event = @event.amoeba_dup
      @event.user_id = current_user.id
      @event.event_image = @image
      @event.save
    redirect_to :back
  end
end 

我添加了@image 行,希望能解决附件问题。当我检查元素时,显示应该找到 th

【问题讨论】:

  • 能否将amoeba_dub方法粘贴到Event上?
  • 使用了这个宝石:github.com/rocksolidwebdesign/amoeba
  • 找到了另一种无需重复的方法,无论如何感谢佩德罗的帮助:D

标签: ruby-on-rails upload duplicates paperclip


【解决方案1】:

尝试类似:

    class EventsController < ApplicationController    
      def calee
        @event = Event.find(params[:id])
        new_event = @event.dup
        new_event.user_id = current_user.id
        new_event.save
        redirect_to :back
      end
    end 

【讨论】:

    猜你喜欢
    • 2012-07-03
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 2011-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多