over 4 years ago

http://www.jacopretorius.net/2013/11/allow-users-to-remove-uploaded-images-with-paperclip.html

實作paperclips的delete image時一種做法是在update時送出params[:remove_avatar]的值給Model判斷再動作
但會遇到Model沒有remove_avatar的Attribute而發生Undefined Method Error
這時可以在Model內加上attr_accessor這個指令,讓model可以接收:remove_avatar的值

class User < ActiveRecord::Base
  attr_accessor :remove_avatar
  attr_accessible :remove_avatar  # rails4改成strong params
end
← 好用資訊 裝機實務 →
 
comments powered by Disqus