My site is for publishing reviews of albums called Pins. The contact model has the following attributes:
: artist ,: year ,: title ,: rank ,: description and: image
The image uses Paperclip and is stored on Amazon S3, if that matters.
I am trying to allow a user to view a review that has been posted by another user and click the link to just write their own review for the same album. Thus, basically the link displays them on the Pin.new page, and the form already has: artist ,: title ,: image and: year.
I figured out how to do this by bringing ALL attributes, including: description and: rank, which I don't want. I am also not able to transfer the image to a new form.
Here is the pins_controller.rb code that I am using:
def copy
@source = Pin.find(params[:id])
@pin = @source.dup
render 'new'
end
And in my view:
<%= link_to "copy", copy_pin_path(params[:id]) %>
So the first question is how @ source.dup: artist ,: title and: year
Question two is how to transfer the image of a paper clip. I tried adding this to my pins_controller.rb:
def copy
@source = Pin.find(params[:id])
@pin = @source.dup
@pin.image = @source.image
render 'new'
end
but it didn’t work.
UPDATE: miller350 answered my first question, but I still can’t get the image of the paper clip to copy to the “new” form. In the console, I can copy Pin from one record and save the new output as follows:
r = Pin.new
r.image = Pin.find(83).image
r.save
I think the problem is that the new pin shape requires the image to be selected from the user's PC before saving the pin. Whatever the Paperclip function, I think that is where I get stuck.