이 간단한 계산 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>`
나는 다음 페이지로 @height 및 @weight 과거에이 방법을 사용하고
`<form action="http://localhost:3000/bmi/[email protected]&[email protected]"` >
이 GET
라고 내가 사용하는 방법을 계산? 그러나 각각 표준 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
일을 발견했다.
아무도 그 이유를 설명 할 수 있습니까?