Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Rubyʵ¼ù—Óû§µÇ¼

¿ª·¢»·¾³
Ruby:Ruby1.9.1
Rails:Rails2.3.5
Mysql:Mysql5.0.9
Driver:mysql-2.8.1-x86-mingw32.gem
IDE:Rubymine2.0.1
Ò»¡¢´´½¨View/login
ÔÚView/loginÏ´´½¨login.html.erb¡¢index.html.erb¡¢loginFail.html.erb
login.html.erb´úÂëÈçÏ£º
<h1>Welcome to login!</h1>
<% form_tag do %>
<table>
<tr>
<td>User name:</td>
<td><%= text_field("user", "username") %></td>
</tr>
<tr>
<td>Password:</td>
<td><%= password_field("user", "hashed_password") %></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=" login " /> <input type="reset" value=" reset " /></td>
</tr>
</table>
<% end %>

index.html.erb´úÂëÈçÏ£º
<h1>Choose a page to look!</h1>
<p><%= link_to 'Users', :controller=>"users",:action=>"index" %></p>
<p><%= link_to 'Products', :controller=>"products",:action=>"index"%></p>
<p><%= link_to 'Logout', :action=>"login"%></p>
loginFail.html.erb
<h1>Invalid user/password combination</h1>
<%form_tag do%>
<%= link_to 'Back', :action=>"login" %>
<%end%>
¶þ¡¢´´½¨login_contoller.rb
´úÂëÈçÏ£º
class LoginController < ApplicationController
def login
if request.get?
session[:user_id] = nil
@user = User.new
else
@user = User.new(params[:user])
logged_in_user = @user.try_to_login
if logged_in_user
session[:user_id] = logged_in_user.id
redirect_to(:action => "index")
else
# flash[:notice] = "Invalid user/password combination"
redirect_to(:action => "loginFail")
end
end
end
def loginFail

end
#Çå¿ÕµÇ¼ÐÅÏ¢
def reset
params[:user]["username"]=null


Ïà¹ØÎĵµ£º

rubyµÄÀàÓëÄ£¿é£¨1£©

class Point
@x = 1
@y = 2
def initialize(x,y)
@x,@y = x,y
end
end 
´úÂëÖеÄ@x£¬@yΪʵÀý±äÁ¿£¬ÊµÀý±äÁ¿Ö»¶ÔselfµÄ»·¾³Æð×÷Óã¬Òò´ËinitializeÍâÃæµÄ@x=1£¬@y=2Ö»¶ÔÀà±¾ÉíÆð×÷Ó㬶ø·½·¨ÄÚ²¿£¬µÄ@x£¬@yÊǶԶÔÏóµÄʵÀýÆð×÷Óõġ£
class Point
include Enumerable
def initialize(x ......

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

ÕâÊÇÒ»¸ö¿ªÔ´£¬Ãâ·Ñ£¬ÁéÇÉ£¬¼òÒ×µÄweb×Ô¶¯»¯²âÊÔ×éºÏ¿ò¼Ü£»Í¨³£Çé¿ö£¬¿ªÔ´µÄ¶«Î÷×ÜÊǸøÈËÒÔÃÔÈË£¬¿ª·ÅʽµÄ´¥¸Ð£¬µ«Í¬Ê±£¬Ò²ÈÃÈËÄÑÒÔ¿ìËÙ½Ó½ü£¨ÏñÊǶ«·½ÄÐÈË¿´´ýÎ÷·½ÃÀÅ®£©£»ÒªÁ˽âÒ»¸ö¿ªÔ´¶øÇÒ×éºÏƯÁÁµÄ¿ò¼Ü£¬×ÜÊÇÒª·ÑЩÖÜÕÂ......×ܶøÑÔÖ®£¬Ëü²»»áÏñÊշѵĶ«Î÷£¬ÄãºÜÌÖÑáËü£¬µ«²»¿É·ñÈÏ£¬ÄãµÄ¸¶·ÑÆäʵ»»È¡Á˱ðÈ˵ÄËöËéÀͶ ......

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: ......

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(' ......

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))
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ