Image upload example?

I need a simple image upload template for uploading a jpeg to the
server…


Anthony E.
Ph: 408-656-2473
var (bonita, farley) = new Dog;
farley.barks(“very loud”);
bonita.barks (“at strangers”);

http://chovy.dyndns.org/resume/
http://utuxia.com/consulting

From chapter 11 of Ruby on Rails for Dummies:
Contents of Migration
def self.up
Create_table :photos do |t|
t.column :picture, :blob
t.column :description, :text
end
end

def self.down
drop_table :photos
end

Contents of _form.rhtml
<%= error_messages_for ‘photo’ %>

Picture
<% file_field 'photo', 'photo' %>

Description
<% text_area 'photo', 'descriptionphoto' %>

Contents of edit.rhtml

Editing photo

<%= start_form_tag( { :action => 'update', :id => @photo }, :multipart => true) %> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <%= end_form_tag %>

Good luck!

On Nov 19, 1:42 pm, Denise R. [email protected]
wrote:

 drop_table :photos

Contents of edit.rhtml

Editing photo

<%= start_form_tag( { :action => 'update', :id => @photo }, :multipart => true) %> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <%= end_form_tag %>

Thanks, but there is no controller?

Use a plugin:

http://svn.techno-weenie.net/projects/plugins/attachment_fu/

HTH,
Nicholas

Nicholas H. wrote:

Use a plugin:

http://svn.techno-weenie.net/projects/plugins/attachment_fu/

HTH,
Nicholas

bit overkill for what I need – i just was curious how I would integrate
a controller into this, or where methods should go. anyway, its a start.

Nicholas H. wrote:

How about this:

Peak Obsession

On Nov 19, 10:27 pm, “Anthony E.” [email protected]

thanks

How about this:

http://manuals.rubyonrails.com/read/chapter/56

On Nov 19, 10:27 pm, “Anthony E.” [email protected]

Denise R. wrote:

The book has good explanations of what everything is doing. Even if you
don’t want to buy the book, you could run down to your local book store
and check it out.

excellent…found the source too:
http://users.drew.edu/bburd/RubyOnRails/

chovy wrote:

On Nov 19, 1:42 pm, Denise R. [email protected]
wrote:

 drop_table :photos

Contents of edit.rhtml

Editing photo

<%= start_form_tag( { :action => 'update', :id => @photo }, :multipart => true) %> <%= render :partial => 'form' %> <%= submit_tag 'Edit' %> <%= end_form_tag %>

Thanks, but there is no controller?

Sorry.

In photos_controller:
def get_picture
@photo=Photo.find(params[:id])
send_data(@photo.picture, :type=> ‘image/jpeg’)
end

In Photo model:
def photo=(photo_in)
self.picture = photo_in.read
end

Contents of new.rhtml

New photo


<%= start_form_tag( { :action => ‘create’ },
:multipart => true) %>
<%= render :partial => ‘form’ %>
<%= submit_tag ‘Create’ %>
<%= end_form_tag %>

Modify show.rhtml with this line (presumably this was scaffolded and
then he suggesting adding this one line):
<img src=“<%url_for( :action => “get_picture”, :id => @photo.id ) %>”
/>


which is shown just above this (likely scaffolded) line:
<%=photo.description %>

There’s a tweak to the listing page too - looks like he replaced the
table cells that were scaffolded with this:

@photo.id ) %>" height="100" /> <%= photo.send("description') %>

The book has good explanations of what everything is doing. Even if you
don’t want to buy the book, you could run down to your local book store
and check it out.

Anthony E. wrote:

Denise R. wrote:

The book has good explanations of what everything is doing. Even if you
don’t want to buy the book, you could run down to your local book store
and check it out.

excellent…found the source too:
http://users.drew.edu/bburd/RubyOnRails/

Perfect. :slight_smile: