Hi,
assuming I have a db table "Items" like this:
CREATE TABLE items (
    id INTEGER NOT NULL AUTO_INCREMENT,
    product_id INTEGER NOT NULL,
    name VARCHAR(30) NOT NULL,
    description VARCHAR(500) NOT NULL,
    imageurl VARCHAR(55),
    imagethumburl VARCHAR(55),
    price FLOAT NOT NULL,
    address_id INTEGER NOT NULL,
    seller_contact_info_id INTEGER NOT NULL,
    totalscore INTEGER NOT NULL,
    numberofvotes INTEGER NOT NULL,
    primary key (id),
    foreign key (address_id) references addresses(id),
    foreign key (product_id) references products(id),
    foreign key (seller_contact_info_id) references 
seller_contact_infos(id)
);
and I want to do the image upload inside a form - can I extend the 
"Item" model in order to let me handle the file upload? Any pointers
in
the right direction would be much appreciated :)
Regards,
Robert
-- 
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
-~----------~----~----~----~------~----~------~--~---
Robert Spielmann wrote:> Hi, > > assuming I have a db table "Items" like this: > > ... > > and I want to do the image upload inside a form - can I extend the > "Item" model in order to let me handle the file upload? Any pointers in > the right direction would be much appreciated :) > > Regards, > RobertTry looking at the FlexImage plugin: http://beautifulpixel.com/flex_image/index.html But if you want to roll your own, then you need to add a binary column to your database table. Form: <%= form_tag :action => ''create'' %> <%= file_field ''some_model'', ''data'' %> <%= submit_tag ''Upload!'' %> <%= end_form_tag %> Controller Action: def create @some_model = SomeModel.new # must call the read method on uploaded file to convert # them to strings @some_model.data = params[:some_model][:data].read @some_model.save end -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the hint, I''ll look into it. I don''t want to store the image into the db though, but as a file on the server. -- 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 -~----------~----~----~----~------~----~------~--~---
Robert Spielmann wrote:> Thanks for the hint, I''ll look into it. I don''t want to store the image > into the db though, but as a file on the server.In that case: #view <%= file_field_tag ''file'' %> #controller File.open("#{RAILS_ROOT}/path/to/file") do |f| f.write params[:file].read end -- 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 -~----------~----~----~----~------~----~------~--~---
Yeah - the only thing missing then is validation :) -- 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 -~----------~----~----~----~------~----~------~--~---