开发者

IF Statements in Ruby [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

Assuming I have have a text box and a button on a page written in Rails what would be the code to compare a string inputted in that box with another string (non-dynamic开发者_开发知识库)?

Does Rails have the same structure as Java when testing If statements like:

IF text1 = text2 Then
... do something ...
Else
... do something ...

Thanks, Nick


if text1 == text2
  ...
elsif text2 == text3
  ...
else
  ...
end

http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Control_Structures#if_expression

http://www.ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#if


In controller

if params[:text_box_name_1].to_s == params[:text_box_name_2].to_s

  ----
else

end


I think this might help: http://www.howtogeek.com/howto/programming/ruby/ruby-if-else-if-command-syntax/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜