开发者

Multiple paperclip uploads for a record breaks new and edit functions

开发者 https://www.devze.com 2023-02-18 14:00 出处:网络
I followed a tutorial on how to add multiple paperclip uploads for a record using nested attributes which seemed to work fine however I now have a problem where I can\'t edit any existing records or a

I followed a tutorial on how to add multiple paperclip uploads for a record using nested attributes which seemed to work fine however I now have a problem where I can't edit any existing records or add any new ones. But I can upload photos to existing records through the edit form.

On editing or saving a new record the app redirects but none of the field contents save, so a new record will save with all fields as nil and on editing a record none of the changes save.

Venue model

class Venue < ActiveRecord::Base
  attr_accessible :venuephotos_attributes
  belongs_to :area
  belongs_to :venuetype
  has_many :reviews
  has_many :venuephotos

  accepts_nested_attributes_for :venuephotos, :allow_destroy => true

  scope :with_type, lambda { |types|
    types.present? ? where(:venuetype_id => types) : scoped }

  scope :with_area, lambda { |areas|
    are开发者_运维百科as.present? ? where(:area_id => areas) : scoped }

  def to_param
    "#{id}-#{name.gsub(/\W/, '-').downcase}"
  end
end

If I remove the attr_accessible :venuephotos_attributes line the new and edit pages work again.

Thanks for any help!


Just noticed on the tutorial that the attr_accessible also includes the names of all the other field names. Which I've added and it works fine now, but is this best practice? I'm super new to programming is there some security issue with attr_accessible?

0

精彩评论

暂无评论...
验证码 换一张
取 消