file upload ...

Jai zenag
2008-07-18T08:36:17Z

i cant able to insert filename into database...pl;s help

my

model.rb
class Mobile < ActiveRecord::Base
validates_presence_of:image

validates_presence_of:brand
  def mobile=(picture_field)
    self.image =
picture_field[''image''].respond_to?(:original_filename)
? base_part_of(picture_field.original_filename) : nil

  end
 def self.save(product)
  name=product[''image''].original_filename
 path = File.join("public/data", name)
 File.open(path, "wb") { |f|
f.write(product[''image''].read) }

end
end
.........................................................
  controller.rb

def create
@mobile=Mobile.new(params[:mobile])
if @mobile.save
post=Mobile.save(params[:mobile])
redirect_to  :action=>''list''
else
render :action=>''new''
end
 end
...........................................

new.rhtml

<%= error_messages_for ''mobile'' %>
<% form_tag ({ :action => ''create'' },
              { :multipart => ''true'' }) do%>
<%=text_field
''mobile'',''brand''%>
<%=file_field
''mobile'',''image''%>
<%=submit_tag ''Submit''%>
<%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?hl=en
-~----------~----~----~----~------~----~------~--~---