Rubyʵ¼ù—HelloWorld
¿ª·¢»·¾³
OS£ºWindowsXP
Ruby: Ruby1.9.1
Rails: Rails2.3.5
IDE: RubyMine2.0.1
1¡¢´´½¨Rails¹¤³Ì
2¡¢ÐÞ¸Ä /config/database.yml
×Ô¶¯´´½¨µÄ¹¤³ÌÖÐĬÈÏÊý¾Ý¿âÁ¬½ÓµÄÊÇsqlite£¬Èç¹ûûÓа²×°´ËÊý¾Ý¿â£¬ÐèÒªÐ޸ĸÃÅäÖ㨱¾ÀýÖÐʹÓõÄÊÇmysql£©
# Mysql Version 5.1.46
development:
adapter: mysql
database: test
username: root
password: root
host: localhost
3¡¢´´½¨Controller
ÔÚapp/controllerÖд´½¨say_controller.rb
´´½¨Íê³Éºó£¬ÔÚ¿ØÖÆÌ¨ÐÅÏ¢Öн«ÏÔʾ´Ë¹ý³Ì´´½¨µÄһϵÁÐÎļþ
C:\Ruby19\bin\ruby.exe -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) E:/Ruby/HelloWorld/script/generate controller -s say
exists app/controllers/
exists app/helpers/
create app/views/say
exists test/functional/
create test/unit/helpers/
create app/controllers/say_controller.rb
create test/functional/say_controller_test.rb
create app/helpers/say_helper.rb
create test/unit/helpers/say_helper_test.rb
Process finished with exit code 0
4¡¢ÐÞ¸Äsay_controller.rb
½«ÄÚÈÝÐÞ¸ÄÈçÏ£º
class SayController < ApplicationController
def hello
end
end
5¡¢´´½¨hello.rhtml.erb
ÔÚapp/views/say Ŀ¼Ï´´½¨hello.rhtml.erb
ÐÞ¸ÄÆäÖеÄÄÚÈÝÈçÏ£º
<html>
<head>
<title>Hello, Rails!</title>
</head>
<body>
<h1>Hello from Rails!</h1>
</body>
</html>
6¡¢ÐÞ¸Äroutes.rb
ÐÞ¸Äconfig/routes.rb£¬ÉèÖÃеÄÓ³É乿Ôò
#·ÓÉÉèÖã¬/say/HelloÊǵØÖ·ÉèÖã»controllerÊǶÔÓ¦µÄcontrollersĿ¼ÏµÄÀ࣬actionÖ¸controllerÖж¨ÒåµÄ·½·¨£¬Çø±ð´óСд
map.connect '/say/Hello',:controller=>"say",:action=>"hello"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
Æô¶¯·þÎñRails·þÎñÆ
Ïà¹ØÎĵµ£º
To get it done is not easy. I spent a whole day to figure out the various compatibility issues along the way out.
Now there still might be potential issues, but it works by my rough test.
Step 1: Install Apache Cassandra
You may know that the Ruby gem cassandra will do it for you.
  ......
¿ÉÓÿ⣺getoptlong.rs£¬ optionparser
¶ÔÓ¦ÀࣺGetoptLong, OptionParser
ǰÕßÒѹýʱ£¬½¨ÒéʹÓúóÕߣ¬ÇÒºóÕß±ÈǰÕßÒ×Óá£
ºóÕßÌØµã£º
1. ²ÎÊýÃèÊöºÍ´úÂë´¦ÀíдÔÚÒ»Æð
2. Êä³ö²ÎÊý˵Ã÷£¬²»Ðèµ¥¶Àά»¤
3. ¿ÉÑ¡²ÎÊýºÍÃüÁî²ÎÊýÃèÊö¼ò½à
4. ²ÎÊý¿É×Ô¶¯×ª»»ÎªÌض¨µÄÀà
5. ......
ת Adding Sound to Your Ruby Apps
Have you ever thought about including sounds in your Ruby application? Used sparingly, sound may enhance your applications by adding audio cues or a custom touch. You could, for example, play a beep or chime that announces the completion of a lengthy process. Per ......
b = "123"
a = b
b.gsub!(/2/,"")
puts a
µÃµ½µÄ½á¹ûÊÇ13£¬·¢ÏÖÈç¹ûa = bµÄ»°Ã²ËÆÖ»ÊǰÑbµÄÖ¸Õë¸øÁËa£¬µ«ÊÇÈç¹ûbµÄÖµ·¢ÉúÁ˱仯a²ÅÄÜ´ÓbÖжÀÁ¢³öÀ´¡£
Èç¹û°ÑÉÏÃæµÄ´úÂë¸Ä³É
b = "123"
a = "#{b}"
b.gsub!(/2/,"")
puts a
ÔòµÃµ½µÄ½á¹ûΪ123£¬ÕâÀïÊǰÑbµÄÖµ¸øÁ ......
ÎÒÃÇÔÚʹÓÃC±à³Ìʱ»áÓöµ½Ò»¸öÎÊÌ⣬±ÈÈçÍ·ÎļþµÄÒ»¸öº¯Êý°üº¬ÔÚÒ»¸ölibÖУ¬µ«ÊÇ
ÔÚʵ¼ÊÁ¬½ÓÖÐÎÒÃDz»ÖªµÀËüÔÚÄĸö¿âÖС£Ò²Ðí¿ÉÐеÄÒ»ÖÖ°ì·¨ÊÇÖ±½ÓÉÏÍø²éѯij¸ö
º¯ÊýµÄÒÀÀµÌõ¼þ£¬Õâ¶ÔÓÚ³£Óú¯ÊýÊÇûÎÊÌâµÄ£¡µ«ÊǶÔÓÚ¸´ÔÓ¶øÓÖȱÉÙÎĵµµÄµÚÈý·½
libÀ´Ëµ£¬ÎÞÒìÓÚ´óº£ÀÌÕë¡£
×Ô´Ëͨ¹ý2ÖÖ°ì·¨À´³¢ÊÔ½â¾öÕâ¸öÎÊÌ⣬ÎÒÃÇÏÈ¿´µÚÒ» ......