Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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

Ruby formµÄÁ½ÖÖд·¨

ÏÂÃæ½éÉÜRuby formµÄÁ½ÖÖд·¨¡£
Ruby formд·¨Ò»£ºÊ¹ÓÃform_for
< % form_for :order, :url => { :action => :save_order } do |form| %>   < p>    < %= label :order, :name, "Name:" %>    < %= form.text_field :name, :size => 40 %>     < /p>   < p>    < %= label :order, :address, "Address:" %>    < %= form.text_area :address, :rows => 3, :cols => 40 %>   < /p>   < p>    < %= label :order, :email, "E-Mail:" %>    < %= form.text_field :email ......

Ruby On Rails 2.0.2Ô´´úÂë·ÖÎö£¨3£© named route


Ç°ÑÔ
  ÔÚ¡¶RoutingµÄÔØÈë¡·ÖУ¬ÎÒ´óÖ½éÉÜÁËÒ»ÏÂRailsÖÐ×î¼òµ¥µÄrouteÊÇÈçºÎ¼ÓÔصġ£ÕâƪÎÄÕ£¬ÎÒ½«À´½²Ò»½²RailsϵͳÖиüΪ¸´ÔÓµÄnamed routeºÍÓëRESTfulÏà¹ØµÄresourceÊÇÈçºÎ±»¼ÓÔصġ£ÎªÁ˲»Öظ´Ì«¶àµÄ±ÊÄ«£¬ÕâƪÎÄÕ½«ÔÚÇ°ÎĵĻù´¡ÉϽøÐУ¬Èç¹û·¢ÏÖµ¥¶À¿´´ËÎÄʱ£¬ÓÐÉÙÐíÔÆÀïÎíÀ½¨ÒéÏÈ¿´Ò»¿´ÎÒµÄǰƪÎÄÕ£ºRuby On Rails-2.0.2Ô´´úÂë·ÖÎö£¨2£©-RoutingµÄÔØÈë
½ø»¯µÄrouting-named route
  Ê×ÏÈ£¬named routeµÄÔØÈëÈ«²¿·¢ÉúÔÚrouting.rbÖС£Æäʵnamed routeÒ»µãÒ²²»±ÈÆÕͨµÄroute¸ßÉîЩʲô£¬RailsÄÚ²¿×îÖÕÒ²Êǽ«named route½âÎöΪһ¸öÆÕͨµÄroute±£´æÔÚRouseSetÀàµÄroutesÊý×éÖУ¨»¹¼ÇµÃÕâ¼Ò»ïô£¿×îºÃÀÎÀμÇסËû£¬ÒòΪ£¬Ëû»¹»áÔÚºóÐøÎÄÕÂÖмÌÐøµÇ̨·¢»ÓÖØÒª×÷Óã©£¬Ö®ËùÒÔÎÒ³ÆËû½ø»¯£¬ÊÇÒòΪnamed route¼ÈÈ»ÌṩÁËname£¬ÔÚRailsÄÚ²¿£¬½«»áÉú³ÉһϵÁеÄhelper·½·¨£¬µ±ÎÒÃÇÔÚcontroller»òÕßviewÖÐʹÓÃlink_to£¬redirect_toµÈ·½·¨Ê±£¬²»ÐèÒªÖ¸¶¨ÏàÓ¦µÄcontrollerºÍaction£¬´Ó¶ø¼ò»¯ÎÒÃǵĴúÂ룬²»ÓöàÁË£¬ÏÈÀ´¿´Ò»¿´ÎÒÃÇËùÊìϤµÄroutes.rb
Ruby´úÂë
ActionController::Routing::Routes.draw do |map|   
  map.purcha ......

Ruby On Rails 2.0.2Ô´´úÂë·ÖÎö£¨3£© resource


RESTfulµÄ»¯Éí----resource
  µ±È»£¬¹â°ÑRESTfulºÍresource³¶µ½Ò»ÆðËƺõÏ൱ÏÁÒ壬ÔÚRailsÖУ¬ActionController::Resources³éÏóÁËRESTÖеÄResource£¬ÕâÀÎÒ²»Ì¸RESTµÄÏà¹Ø¸ÅÄÍøÉÏ×ÊÁÏÒ»´óÛç¡£ÎÒÃǾÍÀ´¿´¿´RailsÖÐÊÇÈçºÎͨ¹ýResourceÀ´ÇáËÉ£¬¼ò±ãµÄÍê³ÉRESTfulÓ¦Óõİɡ£
  resources.rb
  Ô´´úÂë·¾¶£º/actionpack-2.0.2/lib/action_controller/resources.rb
  Ê×ÏÈ£¬ÎÒÃÇÒ²²»ÐèÒª½«resource¿´µÃ¶àôµÄ¸ßÉÄã¿ÉÒÔ°ÑËûÀí½âΪ£¬µ±ÄãÔÚroutes.rbÖж¨ÒåÈçϵÄresourceµÄʱºò£º
map.resources :products
  Rails»á×Ô¶¯ÎªÎÒÃÇÉú³ÉÖÚ¶àµÄnamed route£¬ÕâЩrouteͨ¹ýhttp verbºÍÏàÓ¦µÄcontrollerÖеÄaction¶ÔÓ¦ÆðÀ´£¬µ±È»ÁË£¬ÖÚ¶àµÄhelper·½·¨Ò²Ëæ¼´²úÉú¡£ÈçϱíËùʾ£º
Named Route
Helpers
product
product_url, hash_for_product_url,
product_path, hash_for_product_path
new_product
new_product_url, hash_for_new_product_url,
new_product_path, hash_for_new_product_path
edit_product
edit_product_url, hash_for_edit_product_url,
edit_product_path, hash_for_edit_product_path
...
...
  ´ÓÕâ¸ö½Ç¶ÈÀ´Ï ......

ʹÓÃrubyÓëMS AccessÊý¾Ý¿â½»»¥

ruby³£¹æ·ÃÎÊaccessÊý¾Ý¿âµÄ·½·¨Ó¦¸ÃÊÇʹÓÃDBI¿â
£º
require 'dbi'

DBI.connect("DBI:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;")

¿ÉÊÇ
¼òµ¥³¢ÊÔÖ®ºóûÄܳɹ¦£¬ÌáʾÕÒ²»µ½Çý¶¯Æ÷ADO,ÀÁµÃÔÙÊÔ£¬ËìÕÒÆäËû·½·¨¡£
Ò»·¬ËÑË÷Ö®ºó£¬·¢ÏÖ¿ÉÒÔÓÃWIN32OLEÀ´·ÃÎÊaccess,дһ¸ö¼òµ¥µÄÀà°ü×°Ö®:
require 'win32ole'
class AccessDb
attr_accessor :mdb, :connection, :data, :fields
def initialize(mdb=nil)
@mdb = mdb
@connection = nil
@data = nil
@fields = nil
end
def open
connection_string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
connection_string << @mdb
@connection = WIN32OLE.new('ADODB.Connection')
@connection.Open(connection_string)
end
def query(sql)
recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(sql, @connection)
@fields = []
recordset.Fields.each do |field|
@fields << field.Name
end
......

ʹÓÃrubyÓëMS AccessÊý¾Ý¿â½»»¥

ruby³£¹æ·ÃÎÊaccessÊý¾Ý¿âµÄ·½·¨Ó¦¸ÃÊÇʹÓÃDBI¿â
£º
require 'dbi'

DBI.connect("DBI:ADO:Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;")

¿ÉÊÇ
¼òµ¥³¢ÊÔÖ®ºóûÄܳɹ¦£¬ÌáʾÕÒ²»µ½Çý¶¯Æ÷ADO,ÀÁµÃÔÙÊÔ£¬ËìÕÒÆäËû·½·¨¡£
Ò»·¬ËÑË÷Ö®ºó£¬·¢ÏÖ¿ÉÒÔÓÃWIN32OLEÀ´·ÃÎÊaccess,дһ¸ö¼òµ¥µÄÀà°ü×°Ö®:
require 'win32ole'
class AccessDb
attr_accessor :mdb, :connection, :data, :fields
def initialize(mdb=nil)
@mdb = mdb
@connection = nil
@data = nil
@fields = nil
end
def open
connection_string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='
connection_string << @mdb
@connection = WIN32OLE.new('ADODB.Connection')
@connection.Open(connection_string)
end
def query(sql)
recordset = WIN32OLE.new('ADODB.Recordset')
recordset.Open(sql, @connection)
@fields = []
recordset.Fields.each do |field|
@fields << field.Name
end
......

rubyÀ´Ã¶¾Ùcsdnδע²áµÄÓû§Ãû

require 'open-uri'
$NAME_CHARS= (?a..?z).to_a+(?0..?9).to_a
def is_name_used(name)
str=open('http://passport.csdn.net/UserExist.aspx?UserName='+name)
str=str.read
#str=str.encode('GBK','utf-8')
return true if str[/Red/]
end
def enum_names(len=2)
return if len<2
f=File.open('d:\work\a.txt',"w+")
strpack="A"*len
i,v=0,""
$NAME_CHARS.permutation(len) do |x|
v=x.pack(strpack)
break if v[/^[\d]+/]
#p i+=1
f.puts "#{i+=1} : #{v}"
f.puts "#{v} is not use!" unless is_name_used(v)
end

rescue =>ex
p "err : #{ex.to_s}(#{v})"
ensure
f.close if f
end
......

rubyËæ»úÔÚ¿ØÖÆ̨ÏÔʾ×Ö·û´®

require 'curses'
module Curses
def self.program
main_scr=init_screen
noecho
cbreak
curs_set(0)
main_scr.keypad=true
yield main_scr
end
end
Curses.program do |scr|
max_x=scr.maxx
max_y=scr.maxy
100.times do
scr.setpos(rand(max_y),rand(max_x))
scr.addstr("hi")
end
scr.getch
end
......
×ܼǼÊý:146; ×ÜÒ³Êý:25; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [2] [3] [4] [5] 6 [7] [8] [9] [10] [11]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ