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%>