H开发者_Python百科i 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
You can't send a PUT
request directly from a browser, but you can fake it using Sinatra's method_override
option, which is set to true by default in classic style. If you’re using modular style you’ll have to enable it with enable :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 the POST
method in your form, but to include a hidden input with name "_method" and value "put"
<form name="biodata" action="form" method="post" onsubmit="validateForm()">
<input type="hidden" name="_method" value="put" />
code
</form>
This is the same technique that is used in Rails (in fact it's the same middleware that's used - Rack::MethodOverride
).
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 as PUT
requests -- the browser might be sending them as GET
, which is the default.
Anyway, you should probably just use POST
instead.
精彩评论