Ruby convert expanded if statement into one-liner

时间:2015-05-12 22:15:00

标签: ruby-on-rails ruby if-statement syntactic-sugar

Is there a nicer way to write this if/else statement, given that there’s only a tiny difference between the two parts?

-----  SQL  ------

  if($type == 1){
    $js = "\ndocument.getElementById('next').style.display='hide';";
  }
  else{
    $js = "\ndocument.getElementById('end').style.display='hide';";
  }

  $currentpos = $_SESSION['currentpos'];
  $videourl = $_SESSION['videourl'];
  $cnt = count($_SESSION['queue']); 
  echo <<<EOT
<div id="next">
 <p> Thank you for completing the forms, please click the button below to begin the next clip</p>        
 <a class="btn btn-danger" id="nextbt" value="$currentpos" href="newviewvideo.php?url="$videourl" role="button">Start Next Video</a>

</div>
<div id="end">
<p> Thank you for completing the forms, please click the button below to end</p>
<a class="btn btn-danger" id="endbt" value="$cnt" href="loginhomenew.php" role="button">Login Home</a>
</div>
<script type="text/javascript">//<![CDATA[
 $js
//]]>
</script></body></html>
EOT;
ob_end_flush();

1 个答案:

答案 0 :(得分:3)

I don't recall if custom_made_wrapper.find(" input").prop({disabled: true}) will do what you want or if that's one of those "only check if the attribute exists not the value" ones, but this would work. Not sure it's better though.

:disabled => false