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
have been working on this for ages and would really appreciate any
suggestions.
<--new.rhtml (form)-->
<%= error_messages_for :logo %>
<% form_for(:logo, :url => {:action => ''create''},
:html => { :multipart => true }) do -%>
<p>
<label for="logo">Upload A Logo:</label>
<%= file_field :logo, :uploaded_data %>
<p>
</p>
<p>
<label for="title">Title:</label>
<%= text_field :logo, :title %>
</p>
<p>
<label for="category">Category:</label>
<%= select :logo, :category_id,
Category::CATEGORY_NAMES,
:prompt => "Select a category" %>
</p>
<p>
<%= submit_tag ''Create'' %>
</p>
<% 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
Regards
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---