开发者

sinatra put method is not working

开发者 https://www.devze.com 2023-04-05 13:30 出处:网络
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 va

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号