# Create an ew classified and attach an image with it. def create image_types = ["image/jpeg", "image/pjpeg", "image/gif","image/png", "image/x-png"] @categories = Category.find(:all) @classified = Classified.new(params[:classified]) @classified.user = session[:user] unless params[:classified][:picture].blank? if (image_types.include?params[:classified][:picture].content_type.chomp) @classified.picture = params[:classified][:picture].read else @classified.errors.add(:picture, "Photo doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.") render :action => 'new' return end end if @classified.save redirect_to :action => 'list' else render :action => 'new' end end # Update Method So user can change the image associated with their classified def update image_types = ["image/jpeg", "image/pjpeg", "image/gif", "image/png", "image/x-png"] @classified = Classified.find(params[:id]) @categories = Category.find(:all) if @classified.update_attributes(params[:classified]) unless params[:classified][:picture].blank? if (image_types.include?params[:classified][:picture].content_type.chomp) @classified.picture = params[:classified][:picture].read else @classified.errors.add(:picture, " doesn't seem to be JPG, GIF, or PNG. please ensure it is a valid image file.") render :action => 'edit' return end end flash[:notice] = 'Classified was successfully updated.' redirect_to :action => 'show', :id => @classified else render :action => 'edit' end end
Never been to CodeSnippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
Upload Image To Database (See related posts)
You need to create an account or log in to post comments to this site.
Related Posts
» Delete duplicate rows from a... in mysql sql database db
» Convert MySQL tables to InnoDB in mysql bash database db innodb myisam
» move column in mysql in mysql database
» Creating a MySQL database an... in mysql databases users
» SSH tunneling for MySQL in mysql ssh tunneling remote
» MySQL launchd item for Mac O... in mysql osx 10.4 tiger launchd
Snippets (source code soon to be available) developed by Peter Cooper and powered by Ruby On Rails