锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
django鐨勫師濮嬬爜鏀瑰姩棰戠箒
ORM API 綣佺悙錛堝悗鏉ユ寜ActiveRecord椋庢牸閲嶅啓錛?br />
娌℃湁鏁村悎鐨勬祴璇曟鏋?br />
娌″嚭涔︼紝鏂囦歡鐩告瘮Rails緙轟箣鐢氬
python鍐呴儴鏈変漢瀵筪jango瀹屽叏鐙珛鐨勪竴濂梖ull-stack緋葷粺鏈変笉鍚岀湅娉曪紝鍙堟悶浜嗗緢澶氬埆鐨勬鏋訛紙姣斿turbogears錛?br />
django瀵笰JAX鐑疆鏃犲姩鏂艱》
鐩告瘮璧鋒潵
Rails Team 鐩稿綋紼沖畾錛屽緢灝戝ぇ鏀?br />
ORM 澶紭緹庝簡
鍑虹殑涔︾睄涓綰ф錛屾枃浠朵篃鐩稿綋澶?br />
Ruby 鍥犱負紺劇兢灝忥紝瓚呯駭鍥㈢粨
Full Stack 妗嗘灦錛孶nit Test 鍐呭緩
RJS 璧朵笂 AJAX 鐑疆錛岀倰鐑笉灝戣瘽棰?br />
铏界劧 Open Source 鎶鏈負鏈紝浣嗘槸鎾囧紑 Ruby on Rails 浼樼鐨勬妧鏈笉璋堛?/p>
鍋囧澶у閮戒笉鍐欐枃浠訛紝Ruby on Rails 鐨勬枃浠朵笉澶熷鐨勮瘽錛屾湁浜烘暍鐢ㄤ竴涓笉鐔熸倝鐨勮璦鍚楋紵
娌℃湁灝?Ruby 紺劇兢涓誨姏鏀懼湪 Rails 韜笂錛屽啓寰楀嚭閭i杭澶?API 鍚楋紵
娌℃湁鍥㈢粨鐨勫洟闃燂紝浜哄憳鏉ユ潵鍘誨幓錛屽惖鏉ュ惖鍘葷殑鍥㈤槦浣滃緱鍑哄ソ浣滃搧鍚楋紵
娌℃湁 DHH 鑲姳鍐欑▼寮忎互澶栫殑鏃墮棿鎺ㄩ攢 Rails 錛屽茍涓旇姳鐪懼鏃墮棿鍐欏嚭涓鏈珹gile Web Development with Rails錛屼細鏇村浜烘効鎰忚姳鏃墮棿鍘誨涔犱竴涓惉閮芥病鍚繃錛屼篃娌℃湁鍏徃support 鐨?Ruby on Rails 鍚楋紵
涓鍚戞槸涓鐩樻暎娌欑殑 Open Source 紺劇兢鍙互浠旂粏鎬濊冧竴涓?Ruby on Rails 甯︾粰澶у鐨勫暉紺恒俁uby 紺劇兢鍚戝績鍔涘己錛屼笉鍒嗘暎鍔涢噺錛屽張鎳傚緱鍑轟功浠ュ強鎺屾彙鏃跺娍鐢≧JS鐐掔儹璇濋銆傝繖璇存槑錛屽洟闃熺鐞嗗ソ錛屽悜蹇冨姏寮猴紝琛岄攢寮猴紝姝f槸 Ruby on Rails 鎵╂暎閭i杭蹇熺殑涓誨洜銆傚叾瀹烇紝榪欎笉姝f槸涓涓ソ鍟嗕笟鍥㈤槦搴旇鍏峰鐨勭壒璐ㄥ悧錛?
The behind the scene code generation (aka: magic), the lack of a decent IDE, and worse, of a good debugger made my transition to Ruby somewhat difficult and sometimes confusing frustrating. I used to live in Visual Studio .NET and breath Intellisense. In fact, I still miss that to this day.
Any newcomer to Rails will quickly discover why it is so talked about. First of all, even though I don’t consider myself anywhere near a decent Rails programmer, I am now at least twice as productive with Ruby on Rails than with ASP.NET and C#. Thanks to the MVC (Model, View, Controller), DRY (Don’t Repeat Yourself) and Convention Over Configuration mindset of Rails. All the data access code is automagically generated for you (without running a code generator), templating is built in and creating AJAX’ed applications is a snap.
Life was good with Rails and the more I used it, the more I liked it. That was until early August of 2006. I was ready to launch version 2.0 of Ajaxwhois. Knowing so many professional Rails hackers, I thought deploying my application to my production server was going to be a breeze. I was wrong. Even though the installation of Linux (Ubuntu Dapper Drake 64 bit), Lighttpd, MySql and Mongrel went well, I experienced weird problems, mainly related to Mongrel. Sometimes, my Mongrel instances would simply die and disappear from the process list for no apparent reason. I didn’t have ANY traffic at this point because I hadn’t done DNS transfers yet. On other occasions, Mongrel went crazy and started peaking the CPU at 99%. I had to manually kill and restart it.
After extensive research and countless “from scratch” reinstalls, I found out that Mongrel was known to not play well with 64 bit Ubuntu (I lost the links to this evidence, unfortunately). Mongrel was patched accordingly, but it didn’t solve my problem. It still crashed many times a day and I just couldn’t figure out what was wrong. I asked my good friends Rich Collins and Adam Thorsen (of Guruza.com) who are both experienced Rails developers and they had no idea either. I was stuck.
I wanted to launch. Badly. I didn’t want to waste anymore time with this so I picked up a Python book and rewrote the whole site one more time, in Python using the Django framework this time. I had never programmed in Python before and much less used Django. However, the switch was easy enough since Ruby and Python are somewhat similar.
My experience with Python and Django was great; it is a combination every web developer should consider. However, I soon missed Ruby and Rails. Ruby supports “real” private/public/protected methods (Python just fakes that with its naming convention) and it’s syntax is more forgiving (the need for () at the end of each method call in Python was killing me). Django is not as straightforward as Rails, and requires more code to get things done. There are also many little things that don’t “feel right” in Django, like the need to manually pass variables to a view. Data access is confusing at best while Rails’ ActiveRecord is god-sent. These little things really add up.
On the flip side, Python is faster than Ruby and less memory hungry. I was also surprised to actually love Python’s significant indentation (see example). But more importantly, Python and Django just worked! I never experienced weird crashes like I did with my Rails stack.
So, why am I back to Rails for my next project? 3 letters: FUN. I find Ruby and Rails to be pleasant to use. The community large, active and very helpful. The number of freely available Rails plugins and the fast evolution of the core code are also welcomed additions. Rails requires less code, less self.__awkward_method_calls(), has built-in AJAX and REST support, and has much more flexible data access and templating engines.
But what about those crashes? What about the speed issue? Well, I don’t have the crashes anymore. Don’t ask me why, I don’t know, but it’s fine now, I swear! Something somewhere got fixed and it seems to have solved the problem. However, speed is still one of the low points of Rails. Using caching and proper code optimization should take you a long way, though. Matz, the author of Ruby, is working hard on a new virtual machine that should make Ruby just as fast, if not faster than Python.
My recommendation is, try both for long enough to figure out what works and what doesn’t for you. If you are a long-time Python user, Django might be more compelling for you, but if you are coming from a Java, Perl or Smalltalk background, Ruby and Rails will most likely be what you’ll end up using. Either way, I don’t think you can go wrong.
PS: I don’t want to blame Mongrel for my Rails problems because I am still not sure who was the guilty party. Mongrel is a wonderful piece of software and I heartily recommend it. Just make sure you watch it closely if you use Ubuntu on a 64 bit machine.
灞閮ㄥ彉閲忥紝鏂規硶鍙傛暟鍜屾柟娉曞悕縐板簲璇ョ敤涓涓皬鍐欏瓧姣嶅紑澶存垨鑰呯敤涓涓笅鍒掔嚎寮澶?
鍏ㄥ眬鍙橀噺鐢ㄧ編鍏冪浣滀負鍓嶇紑$;
瀹炰緥鍙橀噺浣跨敤@寮澶達紱
綾誨彉閲忕敤@@
綾誨悕錛屾ā鍧楀悕鍜屽父閲忓簲璇ョ敤澶у啓瀛楁瘝寮澶?/p>
Ruby紼嬪簭浠g爜鐜板湪鐢?浣嶇殑ACSII鐮佹潵琛ㄧず錛岄氳繃璇█鎵╁睍鏉ユ敮鎸丒UC錛孲JIS鎴朥TF-8絳?浣嶇紪鐮佺郴緇熴俁uby2.0鐗堟湰灝嗘敮鎸?6浣嶇殑Unicode緙栫爜
puts print gets
printf "Number: %4.3f, String:%s", 7.8, "hi!"
鏁版嵁綾誨瀷錛氭暟瀛楋紝瀛楃涓詫紝鏁扮粍錛屽搱甯岃〃錛屽尯闂達紝姝e垯琛ㄨ揪寮?br />
1..5 ---> 1,2,3,4,5;
1...5 ---> 1,2,3,4
a=1; b=1.0; a==b #true 姣旇緝涓や釜瀵硅薄鐨勫兼槸鍚︾浉絳?br />
a=1; b=1.0; a.eql?(b) #false 姣旇緝涓や釜瀵硅薄鐨勫間互鍙婄被鍨嬫槸鍚︾浉絳?br />
a=1.0; b=1.0; a.equal?(b) #false 姣旇緝涓や釜瀵硅薄鍦ㄥ唴瀛樹腑鐨勫湴鍧鏄惁鐩稿悓
a=1.0; b=a; a.equal?(b) #true
<=> 姣旇緝涓や釜瀵硅薄鐨勫ぇ灝忥紝澶т簬錛岀瓑浜庯紝灝忎簬 鍒嗗埆榪斿洖1錛?錛岋紞1
===鍙寵竟鐨勫璞℃槸鍚﹀湪宸﹁竟鍖洪棿涔嬪唴錛岃繑鍥瀟rue鍜宖alse
puts (0..9) === 3.14 #true
puts ('a'..'f')==='c' #true
=~鐢ㄦ潵姣旇緝鏄惁絎﹀悎涓涓鍒欒〃杈懼紡錛岃繑鍥炴ā寮忓湪瀛楃涓蹭腑琚尮閰嶅埌鐨勪綅緗紝鍚﹀垯榪斿洖nil
!~鏂█涓嶇鍚堜竴涓鍒欒〃杈懼紡錛岃繑鍥瀟rue錛宖alse
break,璺沖嚭褰撳眰寰幆
next,蹇界暐鏈鐨勫驚鐜殑鍓╀笅閮ㄥ垎錛屽紑濮嬩笅涓嬈$殑寰幆
redo,閲嶆柊寮濮嬪驚鐜紝榪樻槸浠庤繖涓嬈″紑濮?br />
retry錛岄噸澶村紑濮嬭繖涓驚鐜綋
times,upto,downto,each.step
3.times{print 'Hi'} #HiHiHi
1.upto(9) {|i| print i if i<7} #123456
9.downto(1){|i| print i if i<7} #654321
(1..9).each{|i| print i if i<7} #123456
0.step(11, 3){|i| print i} #0369
寮傚父澶勭悊begin/end...rescue...ensure...raise retry鍙互鐢ㄥ湪rescue涓?/p>
attr_writer:motherland
鐩稿綋浜?br />
def motherland=(value)
return @motherland = value
end
attr_reader:motherland
鐩稿綋浜?br />
def motherland
return @motherland
end
attr_accessor:motherland 鐩稿綋浜?attr_reader:motherland; attr_writer:motherland
def user_list @user_pages, @users = paginate(:users, :order_by =錛?'name') end |
錛渢able錛? 錛渢r錛烇紲th錛炲鍚嶏紲/th錛烇紲/tr錛? 錛? for user in @users %錛? 錛渢r錛烇紲td錛烇紲%= user.name %錛烇紲/td錛? 錛? end %錛? 錛?table錛? 錛渉r錛? 錛?= pagination_links(@user_pages) %錛? 錛渉r錛? |
http://www.itpub.net/forum61.html
閲屽ぇ澶氭湁涓嬶紝閲嶇偣鎺ㄨ崘
Programming Ruby 2nd edition
Agile Web Development with Rails
涓浜涗笉閿欑殑璁哄潧 鍙婄綉绔?br />鍥藉唴鐨?br />http://railscn.crispynews.com/
http://www.railscn.com
http://chinaonrails.com
http://r4rclub.schtuff.com/
http://forum.javaeye.com
http://rorwiki.hellopen.net
鍥藉鐨?br />http://www.ruby-forum.com/
http://www.rubyonrailsforum.com/rails-code-questions/
http://rubyforge.org/
http://www.rubyonrails.org/
http://www.ruby-lang.org/en/
http://www.webrick.org/
http://www.yaml.org/
blog
<鍗氬>
閾侀亾鎾錛氭湁璇稿瑙嗛鏁欑▼
http://rorcast.blogger2blogger.com/
my4java鐨勬枃瀛楀崥瀹細鏈夊緢澶氭暀紼嬬殑璇戠ǹ銆佺瑪璁扮瓑
http://my4java.itpub.net/
cnruby閬撳枩鎶鏈棩璁幫細浼楀瀹炰緥鏁欑▼
http://www.hhtong.com/blog1/
caphe鐨勫崥瀹?
http://m.tkk7.com/cap
Caiwangqin鐨勫崥瀹?
http://www.uuzone.com/blog/uu_1115110/
涓枃RubyOnRailsWiki
http://rorwiki.hellopen.net/index.p...%A6%96%E9%A1%B5
鍏充簬rails鍜宎jax鐩哥粨鍚?br />http://www.rubynoob.com/
榪欎釜褰撲腑鏈変竴浜涗粙緇?br />http://www.railscn.com/about704.html