I''ve got a listing model and an image model. The image model contains
1 image per listing, but I wanted to separate out the blob to it''s own
table so that the listing search won''t be slowed.
In my listing''s create method I have this:
def create
@listing = Listing.new(params[:listing])
if @listing.save
if @params[''image''][''tmp_file''].length
> 0
@params[''image''][''image_data''] =
@params[''image''][''tmp_file''].read
@params[''image''].delete(''tmp_file'')
@image = Image.new(@params[''image''])
@image.save
end
flash[:notice] = ''Listing was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
This errors out with an error like so:
undefined method `read'' for "DCP00632.JPG":String
yet, when I have the same image saving code in the image_controller it works
def create
@params[''image''][''image_data''] =
@params[''image''][''tmp_file''].read
@params[''image''].delete(''tmp_file'')
@image = Image.new(@params[''image''])
if @image.save
flash[:notice] = ''Image was successfully created.''
redirect_to :action => ''list''
else
render :action => ''new''
end
end
is the check for length promoting the file field to a string, if so,
how would I check to make sure that they''ve actually specified an
image before I try to save it?
--
Marlon
Hi ! 2005/10/18, Marlon Moyer <marlon.moyer@gmail.com>:> undefined method `read' for "DCP00632.JPG":StringThat's the killer - your form is not multipart encoded. Put this in your options to enable file uploading: <%= start_form_tag({}, {:multipart => true}) %> ... <%= end_form_tag %> Bye ! François _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Jeez! I had the multipart declaration in the image form, but not the listing form. I will shrink back into my cave now! Thanks Francios Marlon On 10/18/05, Francois Beausoleil <francois.beausoleil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi ! > > 2005/10/18, Marlon Moyer <marlon.moyer-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > undefined method `read'' for "DCP00632.JPG":String > > That''s the killer - your form is not multipart encoded. Put this in > your options to enable file uploading: > <%= start_form_tag({}, {:multipart => true}) %> > ... > <%= end_form_tag %> > > Bye ! > François > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- Marlon "And I Sleep, and I dream of the person I might have been, and I''ll be free again And I Speak, like someone who''s been to the highest peaks, and back again And I Swear, that my grass is greener than anyones, until I believe again"