この簡単なBMI計算ウェブプログラムですGETとPOSTの両方で値を渡す方法は?
BMI_controller.rb
class BmiController < ApplicationController
def enter
end
def calculate
@height = params[:height].to_f
@weight = params[:weight].to_f
@bmi=(@weight/(@height*@height))
@category
if @bmi<18.5
@category= "Underweight"
end
if @bmi>18.5 and @bmi<23
@category="Normal"
end
if @bmi>23 and @bmi<25
@category= "Overweight"
end
if @bmi>25
@category="Obese"
end
end
end
calculate.html.erb
<p>Height: <%= @height %></p>
<p>Weight: <%= @weight %></p>
<p>BMI: <%= @bmi %></p>
<p>Category: <%= @category %></p>
Enter_data.html.erb
`<h1>Welcome to BMI Calculator</h1>
<form action="http://localhost:3000/bmi/[email protected]&[email protected]" >
<p>Height: <input type="text" name="height"></p>
<p>Weight: <input type="text" name="weight"></p>
<br><br>
<input type="submit" namevalue="Calculate" >
</form>`
私は私が使用しての方法は、それがGET
と呼ばれている次のページに@heightと@weight過去にこの方法を使用して
`<form action="http://localhost:3000/bmi/[email protected]&[email protected]"` >
を計算しますか? しかし、それぞれ標準method="get"
とmethod="post"
を行う方法は?
更新
しかし、私はあまりにも<form action="http://localhost:3000/bmi/calculate?height=1&weight=23212" >
または<form action="Calculate" >//<<=this should refer back to the function- calculate
仕事を見つけました。
誰でも説明できますか?