My site is for posting album reviews, which are called Pins. The pins 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 see a review that another user posted and click a link to more simply write their own review for that same album. So basically the link takes them to the Pin.new page and the form already has the :artist, :title, :image, and :year filled in.
I figured out how to do it while bringing ALL of the attributes, including the :description and :rank, which I don't want. I am also not able to bring over the image to the new form.
Here is the pins_controller.rb code I'm using:
def copy
@source = Pin.find(params[:id])
@pin = @source.dup
render 'new'
end
And in my show view:
<%= link_to "copy", copy_pin_path(params[:id]) %>
So question one is how to @source.dup only :artist, :title, and :year
question two is how to bring over the paperclip image. 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 that didn't work.
UPDATE: miller350 answered my first question, but I still can't get the paperclip image to copy over to the "new" form. In the console I can copy from one Pin record and save a new pin like this:
r = Pin.new
r.image = Pin.find(83).image
r.save
I think the issue is that the new pin form requires that an image is chosen from the user's PC before saving the pin. Whatever that function of Paperclip is, I think that is where I'm getting stuck.