sinatra put 方法不起作用
您好,提交表单时,“put”方法用于将数据从表单发送到 sinatra。put 方法在 app.rb 中定义,put 方法调用显示两个值的 erb 文件。
但没有显示任何内容,有人可以帮忙吗?
put '/form' do
@name = params[:FirstName]
@last = params[:LastName]
erb :formact
end
表格
<form name="biodata" action="form" method="put" onsubmit="validateForm()">
code
</form>
谢谢
Hi on submission of the form 'put' method is used to send data from form to sinatra.the put method is defined in app.rb put method makes a call to erb file which displays the two values.
but nothing is being displayed could somebody help please.
put '/form' do
@name = params[:FirstName]
@last = params[:LastName]
erb :formact
end
form
<form name="biodata" action="form" method="put" onsubmit="validateForm()">
code
</form>
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法直接从浏览器发送
PUT
请求,但您可以使用 Sinatra 的method_override
选项,在经典风格中默认设置为 true。如果您使用模块化样式,则必须使用enable :method_override
启用它。这会检查传入的请求是否包含名为
_method
的参数,如果找到,则调用的请求方法将更改为该参数的值,以便应用程序的其余部分认为该调用是使用该参数进行的HTTP 方法。让
put
方法正常工作的方法是在表单中使用POST
方法,但要包含名称为“_method”、值“put”的隐藏输入。与 Rails 中使用的技术相同(事实上,它与使用的中间件相同 -
Rack::MethodOverride
)。You can't send a
PUT
request directly from a browser, but you can fake it using Sinatra'smethod_override
option, which is set to true by default in classic style. If you’re using modular style you’ll have to enable it withenable :method_override
.This checks incoming requests for a parameter named
_method
, and if it finds one the request method of the call is changed to the parameter's value so it appears to the rest of the app that the call was made using that HTTP method.The way to get your
put
method to work is to use thePOST
method in your form, but to include a hidden input with name "_method" and value "put"This is the same technique that is used in Rails (in fact it's the same middleware that's used -
Rack::MethodOverride
).我不认为
PUT
是表单提交的有效方法。检查您的 HTTP 服务器日志,看看请求是否实际上以PUT
请求的形式发出——浏览器可能会以GET
的形式发送它们,这是默认情况。无论如何,您应该只使用
POST
来代替。I don't think
PUT
is a valid method for form submission. Check your HTTP server log and see if the requests are actually coming asPUT
requests -- the browser might be sending them asGET
, which is the default.Anyway, you should probably just use
POST
instead.