Multip;e upload

Hey,

I have managed to successfully implement image upload using the
attachment_fu plugin. I require to upload multiple images, possibly each
with a different title and category. I have provided my code below. I
would really appreciate any suggestions.

<–new.rhtml (form)–>
<%= error_messages_for :logo %>

<% form_for(:logo, :url => {:action => ‘create’},
:html => { :multipart => true }) do -%>

Upload A Logo: <%= file_field :logo, :uploaded_data %>

Title: <%= text_field :logo, :title %>

Category: <%= select :logo, :category_id, Category::CATEGORY_NAMES, :prompt => "Select a category" %>

<%= submit_tag 'Create' %>

<% end -%>

<–upload_controller.rb–>
class UploadController < ApplicationController

def index
@logo = Logo.find(:all, :conditions => {:parent_id => nil}, :include
=> :category)
end

def new
@logo = Logo.new
end

def create
@logo = Logo.new(params[:logo])
if @logo.save
flash[:notice] = ‘Logo was successfully created.’
redirect_to :controller => ‘upload’, :action => ‘index’
else
render :action => :new
end
end

def show
@logo = Logo.find(params[:id])
end

def delete
@logo = Logo.find(params[:id])
if @logo.destroy
flash[:notice] = ‘Deleted’
redirect_to :action => ‘index’
end

end

end

<–logo.rb (model)–>
class Logo < ActiveRecord::Base

belongs_to :category

has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => ‘320x200>’,
:thumbnails => { :thumb => ‘100x100>’ }

validates_as_attachment

end

Rgeards

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs