2023-08-21 05:34PM
参考:https://www.ruby-toolbox.com/categories/rails_file_uploads
参考:https://ruby-china.github.io/rails-guides//form_helpers.html#uploading-files
两个表单都用于上传文件
<%=
form_tag({action:
:upload
}, multipart:
true
)
do
%>
<%=
file_field_tag
'picture'
%>
<%
end
%>
<%=
form_for
@person
do
|f|
%>
<%=
f.file_field
:picture
%>
<%
end
%>
将有权访问控制器上传的文件,如下所示:
def
upload
uploaded_io = params[
:person
][
:picture
]
File
.open(Rails.root.join(
'public'
,
'uploads'
, uploaded_io.original_filename),
'wb'
)
do
|file|
file.write(uploaded_io.read)
end
end
登录
请登录后再发表评论。
评论列表:
目前还没有人发表评论