Skip to content

Instantly share code, notes, and snippets.

@ecpplus
Created September 13, 2011 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecpplus/1214465 to your computer and use it in GitHub Desktop.
Save ecpplus/1214465 to your computer and use it in GitHub Desktop.
Railsでファイルアップロードするとき
<%= form_for :user, :url => {:action => :create}, :html => {:method => :post, :multipart => true} do |f| %>
<%= f.text_filed :name %>
<%= f.file_filed :image %>
<% end %>
def create
@user = User.new(:name => params[:user][:name])
if params[:user][:image].present?
File.open(filepath, 'wb') do |f|
f.write(params[:user][:image].read)
end
end
@user.save!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment