Welcome to Working With Rails

 

Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
Paperclip get param data in update action
5 Posts
Paperclip get param data in update action

Thanks Ganesh,

These lines of code solved the problem: def photo_attributes=(photo_attributes) photo_attributes.each do |attributes| photos.build(attributes) if !attributes[:image].blank? end end

Hi Wouter,

http://www.webyfi.com/?p=11

This article will help you more..!

Good Luck..!

Person
Jruby, Ruby, Rails Programmer
Sign In To Rate Post

Hi Ganesh,

Thanks for your help, I'll show an example of my code (http://pastie.org/727904)

At the end I've included update.html.erb for testing. As you can see, I retrieve something, but I'd like to get the real photo data.

Can you help me with this?

Hi Wouter,

You can access new array(picturs) content like:

ex : Im considering edit form as:

{ :multipart => true } do |person_form| %>

First name: 
Last name : 


   Enxisting  image: 

Now in your controllers :update function will be:

def update @person = Person.find(params[:id])

if @person .update_attributes(params[:person]) params[:person][:newphotos] ||= [] @personNewPhotos = params[:person][:newphotos]

@personNewPhotos.each do |newPhoto| @photo = @person.photos.new @photo.image = newPhoto @photo.save end end end

I hope this will help you..

Good Luck..!

:) :)

Person
Jruby, Ruby, Rails Programmer
Sign In To Rate Post

Hello,

I'm using paperclip to add pictures to a project. One project can have multiple pictures so I've added multiple fields. (that's working fine) But when I update a project with empty (picture)fields, paperclip is creating empty entries in the photo model.

So my question is, how can I get the newly added pictures in an array? I've tried params[:project][:data] but that isn't returning anything.

Thanks

5 Posts
Login to add your message