Reputation: 31
i have a rails app with user inputs, i have to perform a calculation and store its new value. eg of price is given which was earlier written in js and php
if(count($_POST['price']) >= 0 && !empty($_POST['price']))
{
$price = $_POST['price'];
$sql .= " '". $price ."', ";
switch ($price){
case ($price >= 0 && $price <= 21):
$price_rating = 0;
break;
case ($price >= 22 && $price <= 29):
$price_rating = 5;
break;
case ($price >= 30 && $price <= 39):
$price_rating = 7;
break;
case ($price >= 40 && $price <= 49):
$price_rating = 8;
break;
case ($price >= 50 && $price <= 59):
$price_rating = 6;
break;
default:
$price_rating = 0;
}
}
else
{
$price_rating = 0;
$sql .= " '', ";
}
Upvotes: 0
Views: 39
Reputation: 980
everything is the same... in the according controller you just need to do
@price = params[:price] (which is the same as $price = $_POST['price'];)
if (0..21).include?(@price)
@price_rating = 0
if ... and so on
Upvotes: 1