Jean-David,
Here's a bit of code from an old project of mine:
def update
data = params[:product].delete('data') # HashWithIndifferentAccess still needs the actual key type to .delete
begin
@product = Product.find(params[:id], :conditions => { :virtual => true })
unless data.blank? # i.e., not replacing image
content = data.read
if content.blank?
flash[:error] = "Selected upload file was empty"
redirect_to :action => 'edit'
return
end
@product.image_size = ImageSizer.of_blob(content).size
filename = Product.get_local_image_name data.original_filename
File.open(File.join(RAILS_ROOT, 'public', filename), 'wb') do |f|
f.write content
end
@product.image = filename
end
respond_to do |format|
if @product.update_attributes(params[:product])
…
end
Note that I am removing the 'data' key from the attributes hash params[:product] so that it isn't used in the .update_attributes call later. Perhaps you need to remove the 'illustration' since you've already handled that portion of the update.
If you know that the illustration is changed, but ActiveRecord doesn't, then perhaps you need to call @lead.illustration_will_change! to inform AR that the attribute is dirty and needs to be written out.
-Rob
>
>>
>> if @lead.update_attributes( params[:lead] )
>> flash[:success] = "Leaderboard successfully updated."
>> redirect_to @lead
>> else
>> render action: "edit"
>> end
>> end
>>
>>
>> def upload_image
>> if params[:lead][:illustration]
>> uploaded_io = params[:lead][:illustration]
>>
>> File.open(Rails.root.join('app', 'assets', 'images',
>> uploaded_io.original_filename), 'wb') do |file|
>> file.write(uploaded_io.read)
>> end
>>
>> return "#{uploaded_io.original_filename}"
>> end
>> end
>>
>>
>>
>>>
>>> Colin
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to
rubyonrails-ta...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>