6091 comments
2357 subscribers
6237 on Twitter
Subscribe! Feed reader E-mail

Rails: Paperclip needs attributes defined by attr_accessible, not just attr_accessor

I wanted to add uploaded files to the survey response model defined by the Surveyor gem. I’d gotten most of the changes right, and the filenames were showing up in the model, but Paperclip wasn’t saving the files to the filesystem. As it turns out, Paperclip requires that your attributes (ex: :file_value> for my file column) be tagged with attr_accessible, not just attr_accessor.

Once you define one attr_accessible item, you need to define all the ones you need, or mass-assigning attributes with update_attributes will fail. This meant adding a whole bunch of attributes to my attr_accessor list, too.

If you’re using accepts_nested_attributes_for, you will also need to use attr_accessible there, too.

Sharing the note here just in case anyone else runs into it. Props to Tam on StackOverflow for the tip!

2011-04-01 Fri 12:41

Short URL: http://sachachua.com/blog/p/22224

On This Day...

  • 2013: Monthly review: April 2013 — Last month, I wrote: April will be more about slowing down and following up, I think. But this is good. [...]
  • 2012: Sketchnote workflow — I like sketching notes of books and presentations. It forces me to squeeze the information onto one page, and the [...]
  • 2010: Quick guide to domain names — Having your own domain name means being able to use the same e-mail address or website URL for as long [...]
  • 2009: Making things; Vogue 8020 — I’ve been writing a lot about sewing lately, which might surprise you if you came to this blog for tips [...]
  • 2009: Weekly review: Week ending May 10, 2009 — From last week’s plans: Work: Merge development changes into release-4 Work: Build event calendar system Work: Get feedback on presenter guide Work: Attend speed [...]
  • 2008: You have received a painting from Sacha
  • 2008: I need a faster web host — My site’s been slow for a while now – so slow that even I don’t have fun flipping through it. [...]
  • 2006: Refreshed — Whenever I slow down and let the universe tell me what to do, it gives me back something amazing. I slept [...]
  • 2006: Linux Caffe — I’m sitting in the Linux Caffe working over a wireless connection, having just polished off another cup of their excellent [...]
  • 2006: Books at the Linux Caffe — I’ll be writing another blog post about the Linux Caffe, but here’s a list of the books they have along the [...]
  • 2006: BBC World Documentary on free and open source software in developing countries — Seen on the Toronto Linux Users Group mailing list: http://www.apdip.net/news/fossdoc From the announcement: “Coming Soon: The Code Breakers – a BBC World Documentary [...]
  • 2006: Stretched — I’m starting to feel a little stretched. Too many nights with too little sleep, too many blog entries that are just [...]
  • 2005: Colored index cards — I love posting my productivity ideas because every time I do so, I get comments suggesting even better ways to do [...]
  • 2004: Etask: Gantt charts for Emacs — http://www.reneweichselbaum.com/etask.html Wow, pretty! I should check this out…
  • 2003: Smartphone — - Developing apps for the Microsoft smartphone I wonder if I can use it with Linux… Would the ppp trick described at [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!