Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sinatra put method is not working

Tags:

sinatra

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

like image 793
karthi Avatar asked Jul 09 '26 13:07

karthi


1 Answers

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).

like image 121
matt Avatar answered Jul 13 '26 19:07

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!