[url]http://destiney.com/blog/rails-form-tag[/url]
Consider the api definition for form_tag:
form_tag( url_for_options = {},
options = {},
*parameters_for_url,
&proc)
This form_tag:
<%= form_tag( :action => 'upload',
:multipart => true ) %>
Produces this:
<form action="/home/upload?multipart=true"
method="post">
which is probably not what you want.
Try this instead:
<%= form_tag( { :action => 'upload' },
:multipart => true ) %>
and you'll get this:
<form action="/home/upload"
enctype="multipart/form-data" method="post">
You have to establish when your first hash of parameters ends, otherwise form_tag will assume your :action and your :multipart option are a single hash, when :multipart really needs to go in the second hash.
Consider the api definition for form_tag:
form_tag( url_for_options = {},
options = {},
*parameters_for_url,
&proc)
This form_tag:
<%= form_tag( :action => 'upload',
:multipart => true ) %>
Produces this:
<form action="/home/upload?multipart=true"
method="post">
which is probably not what you want.
Try this instead:
<%= form_tag( { :action => 'upload' },
:multipart => true ) %>
and you'll get this:
<form action="/home/upload"
enctype="multipart/form-data" method="post">
You have to establish when your first hash of parameters ends, otherwise form_tag will assume your :action and your :multipart option are a single hash, when :multipart really needs to go in the second hash.
本文详细介绍了Rails中form_tag的正确用法,展示了如何避免常见错误并生成正确的表单标签,特别是涉及文件上传的情况。
1205

被折叠的 条评论
为什么被折叠?



