Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : Ruby

netbeans + ruby + watir web×Ô¶¯²âÊÔ¿ò¼Ü´î½¨

ÕâÊÇÒ»¸ö¿ªÔ´£¬Ãâ·Ñ£¬ÁéÇÉ£¬¼òÒ×µÄweb×Ô¶¯»¯²âÊÔ×éºÏ¿ò¼Ü£»Í¨³£Çé¿ö£¬¿ªÔ´µÄ¶«Î÷×ÜÊǸøÈËÒÔÃÔÈË£¬¿ª·ÅʽµÄ´¥¸Ð£¬µ«Í¬Ê±£¬Ò²ÈÃÈËÄÑÒÔ¿ìËÙ½Ó½ü£¨ÏñÊǶ«·½ÄÐÈË¿´´ýÎ÷·½ÃÀÅ®£©£»ÒªÁ˽âÒ»¸ö¿ªÔ´¶øÇÒ×éºÏƯÁÁµÄ¿ò¼Ü£¬×ÜÊÇÒª·ÑЩÖÜÕÂ......×ܶøÑÔÖ®£¬Ëü²»»áÏñÊշѵĶ«Î÷£¬ÄãºÜÌÖÑáËü£¬µ«²»¿É·ñÈÏ£¬ÄãµÄ¸¶·ÑÆäʵ»»È¡Á˱ðÈ˵ÄËöËéÀͶ¯³É±¾£¬¸÷ÓÐÀû±×£¨¾ÍÏñijЩÈâÌå½»Ò×ËƵģ©¡£
1.netbeans»¹ÊÇÄǸönetbeans¡£ÆäʵÄãÍêÈ«¿ÉÒÔ²»ÓÃËü£¬¿ÉÒÔÖ±½ÓʹÓüÇʱ¾±àÂ룬ȻºórubyÃüÁîÔËÐС£²»¹ý»¹ÊÇÄǸöÔ­Òò£¬¶ÔÓÚÀÏÊÇÔÚ“Íòǧ”ÏîÄ¿ÖÐתÀ´×ªÈ¥µÄÎÒÃÇÕâЩÈË£¬²»ÏñÄÇЩרעÓÚijһÃÅITÒÕÊõµÄ¿ª·¢Õߣ¬ÎÒÃÇÀϲ»Í£µØ½Ó´¥ÐÂÏîÄ¿£¬Ëü²»´ó£¬È´ºÜ·±Ëö£¬ÒòΪËüÀÏÊǸù¾ÝÎÒÃÇ×Ô¼ºµÄ£¬»òÕß“Àϰ唵ÄÒâÖ¾µ½´¦×ªÒÆ£¬ËùÒÔ£¬»ù±¾ÉÏÎÒÃÇûÓÐÌ«¶àʱ¼äרעijһÃÅÒÕÊõ......ÕâÑù£¬¾ÍÒªÇóÎÒÃǶԴó¶àÊý¶«Î÷¶¼Ï£ÍûËü¾¡¿ì´î½¨ÍêÕû£¬½øÈë²âÊÔʹÓý׶Σ»¶Ô£¬Õâ¾ÍÊÇÎÒÏÖÔڵŤ×÷£¬¹þ¹þ£¡×îа汾netbeans 6.8£¡
2.ruby¡£×îÐÂÒѾ­ÊÇ1.9.1ÁË£¬µ«ÊÇÎÒ»¹ÊÇ°²×°ÁË1.8.6£¬Ô­Òò£¿ºÜ¼òµ¥£¡ÎÒgoogle.com.hkµ½µÄµÚÒ»¸ö¾ÍÊÇËü£¬¹þ¹þ£¡
3.watir¾Í¸Ãϸϸ˵ÁË£¬ºÇºÇ£¬ÒòΪǰÃæÁ½¸ö¼òµ¥µÄÔµ¹Ê£¬Õâ¸ö°²×°ÀíËùµ±È»¸´Ôӵ㣠......

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
&nbs ......

дµÄÒ»¸öinterÀàÄ£·ÂrubyÕûÊýµÄÐÐΪ

ÎÒÃÇÖªµÀrubyÖжÔÓÚÕûÊýµÄ[],[]=,<<,>>²Ù×÷ÊÇÕë¶ÔÓÚ¶þ½øÖƵÄÖµÀ´ÔËËãµÄ¡£
ÎÒÏÖÔÚдһ¸öÕë¶ÔÊ®½øÖÆÊý²Ù×÷µÄÀ࣬ӵÓÐÕûÊýµÄËùÓз½·¨£¬ÈçÏÂ:
class InterEx
def initialize(val=0)
@val=val
end

def to_s
@val.to_s
end

def [](idx)
self.to_s[idx].to_i
end

def []=(idx,val)
s=self.to_s
s[idx] = val.to_s
@val=s.to_i
end

def coerce(other)
[other,@val]
end

def <<(v)
return InterEx.new(@val) if v==0
InterEx.new(@val*10**v)
end

def >>(v)
return InterEx.new(@val) if v==0
s=self.to_s
s=s[0..(-1*v-1)]
InterEx.new(s.to_i)
end

def method_missing(mtd,*args)
InterEx.new(@val.send mtd,*args)
end

end
ruby»¹ÌṩÁËdelegate»úÖƱãÓÚ´úÀíÒ»¸öÀ࣬±ÈÈçÒªÏë´úÀíFixnumÀ࣬
¿ÉÒÔÕâôд:
require 'delegate'
class InterEx<DelegateClass(Fixnum)
...
end

......

RUBYʵ¼ù—Êý¾Ý¿â¼òµ¥²Ù×÷

¿ª·¢»·¾³£º
Ruby:1.9.1
Rails:2.3.5
Rake:0.8.7
Rack:1.0.1
Mysql:5.0.9
Ruby-mysql:mysql-2.8.1-x86-mswin
IDE:RubyMine2.0.1
Êý¾Ý¿â×¼±¸£º
database:dbdevelopment
user:crystal
password:crystal
Ò»¡¢´´½¨RubyÏîÄ¿RorTest
¶þ¡¢ÐÞ¸Ädatabase.yml
ÕâÀïÖ»ÆôÓÃdevelopment»·¾³Êý¾Ý¿â£¬ÐÞ¸ÄÅäÖÃÎļþÈçÏ£º
development:
adapter: mysql
encoding: utf8
reconnect: false
database: dbdevelopment
pool: 5
username: crystal
password: crystal
host: localhost
Èý¡¢ÔËÐÐScaffold
RorTest->New->Scaffold  ÔËÐвÎÊý:Product title:string description:string price:integer
³É¹¦ÔËÐк󣬽«ÔÚ¿ØÖÆ̨ÖÐÊä³öÔËÐйý³ÌÖд´½¨µÄĿ¼¼°Îļþ£¨°üÀ¨Model¡¢Help¡¢ViewµÈ£©
ËÄ¡¢·´ÏòÉú³ÉÊý¾Ý¿â±í
ÔÚdb/migrateÏÂÕÒµ½ÀàËÆ create_products.rbÎļþ£¬ÓÒ¼üRun
³É¹¦ÔËÐкó½«ÔÚ¶ÔÓ¦Êý¾Ý¿âÖÐÉú³Éschema_migrations¼°productsÊý¾Ý±í
Îå¡¢ÐÞ¸Äroutes.rb
ÔÚroutes.rbÖÐÌí¼ÓÓ³Éä¹æÔò
map.connect '/products',:controller=>"product",:action=>"index"
map.connect ':controller/:action/:id'
map.connect ':controller/:action/ ......

Rubyʵ¼ù—will_paginateʵÏÖ·ÖÒ³

¿ª·¢»·¾³£º
OS:Windows XP
Ruby:Ruby1.9.1
Rails:Rails2.3.5
will_paginate:will_paginate2.3.11
(ÔÚÃüÁîÐÐÖÐÔËÐÐ gem install mislav-will_paginate --source http://gems.github.com )
IDE:Rubymine2.0.1
DB:mysql5.0.9
±¾ÀýÔÚÉÏÒ»¸öÀý×Ó£¨Rubyʵ¼ù—¼òµ¥Êý¾Ý¿â²Ù×÷£©µÄ»ù´¡ÉÏʵÏÖ·ÖÒ³£¬ÀûÓõÄÊÇwill_paginate²å¼þ
Ò»¡¢°²×°will_paginate
(ÔÚÃüÁîÐÐÖÐÔËÐÐ gem install mislav-will_paginate --source http://gems.github.com )
¶þ¡¢ÐÞ¸Äenviroment.rb
ÒýÓÃ"will_paginate"£¬ÔÚ
   Rails::Initializer.run do |config|
   end
Ö®ºóÌí¼Ó require 'will_paginate' £¬·ñÔòÔËÐÐʱ±¨´í“method not found 'paginate' ”
Èý¡¢ÐÞ¸Äproduct_controller.rb
ÐÞ¸Ä index ·½·¨ÎªÈçÏÂ:
def index
# @products = Product.all
@products = Product.paginate :page => params[:page]||1, :per_page => 2
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
#×¢:1ÊÇÓû§ÒÔhttp://localhost:3000/products ÏÔʾµÄµÚ1Ò³µÄ ......

ruby on rails Ò»²½²½¿ªÊ¼(2)·ÖÒ³ºÍ¼òµ¥²éѯ

ʹÓà will_paginate ½øÐзÖÒ³ºÍ¼òµ¥²éѯ
ÔÚÃüÁîÐÐÏÂʹÓà gem install will_paginate ÃüÁ³öÏÖÏÂÃæ½á¹û°²×°³É¹¦
´ò¿ª books_controller.rb (Äã×Ô¼ºµÄ¿ØÖÆÆ÷)
×¢Ê͵ô²éÕÒÈ«²¿µÄ·½·¨£¬Ê¹ÓÃÏÂÃæµÄ·½·¨£¬ÒѾ­¼¯³É¸ù¾Ýtitle½øÐвéѯ
Ruby´úÂë
#@books = Book.all   
@books = Book.paginate :page => params[:page],      
                               :per_page => 2,    
                               :conditions => ["title like ?", "%#{params[:search]}%"]    
    respond_to do |format|   
    &nb ......
×ܼǼÊý:146; ×ÜÒ³Êý:25; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [3] [4] [5] [6] 7 [8] [9] [10] [11] [12]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ