190 likes | 325 Views
Ruby on Rails is coming. Cao, ASDC, 20091123. Outline. What’s it Prepare Demos Concepts & Notes Questions Study Experience Refs. What?. Ruby, 松本行弘 (MatsumotoYukihiro, Japan) , http://www.ruby-lang.org/en/ , dynamically interpreted, familiar with command line usage
E N D
Ruby on Rails is coming Cao, ASDC, 20091123
Outline • What’s it • Prepare • Demos • Concepts & Notes • Questions • Study Experience • Refs.
What? • Ruby, 松本行弘(MatsumotoYukihiro, Japan) , http://www.ruby-lang.org/en/ , dynamically interpreted, familiar with command line usage • Rails, just a Web framework, MVC well supported, http://rubyonrails.org/
Prepare • Install ruby 1.8.6(Note: at step3, checked rubygems) test: ruby –v • Install rubygem(go to rubygems-1.3.5) ruby setup.rb gem update –system test: gem -v • Install rails(2.3.4) using gems on command line: gem install rails test: rails -v • Run your first application on command line rails path/to/your/new/applicationName (Create an application skeleton)cd path/to/your/new/applicationName (navigate to app)ruby script/server (start application server, WEBrick, CTRL+Cstop it) Now you can access it by: http://localhost:3000,. Can you look “Welcome aboard”? Note: If there are errors about DB, install default SQLite(gem install sqlite3-ruby) or MySql(Next discussed) • Build our IDE: Aptana RadRails (http://www.radrails.org/download/ ) Standalone(like Eclipse , Recommended) or Eclipse plugin(site: http://download.aptana.com/tools/radrails/plugin/install/radrails-bundle , need eclipse3.4.0) • Other configs below…
Go with MySQL • Install mysql driver: gem install mysql • Copy the mysql dll into ruby/bin directory(http://developer.51cto.com/art/200907/137801.htm ) • Notes(special): ruby1.8.6+ supported mysql, do not install ruby1.8.5 • Create rails application with mysql rails path/appName –d mysql properly configure DB detail in directory: appName/config/dbName.yml (connect to your local or server DB) • Create DB: rake db:create (other tasks, view by rake -T) • DB Migration: rake db:migration
Version Control • SVN Install in Aptana: http://subclipse.tigris.org/update_1.6.x
Flex • Flex可以方便的和传统的Web应用程序整合到一起。Flex提供一个Flash作为客户端,Flash则通过Web服务器来传递数据。Flex应用程序可以通过SOAP或者传统的Http来访问Web服务。也就是说,Flex可以被整合到脚本语言环境中,JSP,ASP,PHP,RUBY都可以和其集成。由于后台的环境可能是JSP、ASP、PHP、RUBY其中的一种。为了保证系统的可移植性,FLEX一般通过API来调用基于SOAP的Web服务,一般来说,是将数据组合成有意义的XML文件,然后在客户端对ActionScript做映射。http://hi.baidu.com/maklak/blog/item/81c7623d1dab1cea3d6d971a.html • ROR(Ruby On Rails)是时下热门的一个Web开发框架,Flex和ROR的整合也很简单。假设这段代码是属于users控制器的,那么只需要把相应view下面的getUser.rhtml置空,然后通过users/get/1来访问即可。其中to_xml是把user转化为XML格式。
Demos • Post Blog(command line from scratch) followed http://guides.rubyonrails.org/getting_started.html Important commands: script/generate scaffold Post name:string title:string content:text rake db:migrate • Login(Aptana) • With Flex/Flash
Concepts&Notes • MVC framework, look components in “” • Assumptions • Difference from Java: http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-java/ • Pass request parameters、Session management • Tags
Scaffold • ruby script/generate scaffold modelName fieldName:fieldType, • ruby script/destroy scaffold modelName
Controllers • ruby script/generate controller Say
Notes • 缺省的,Rails使用与其控制器的action相同的名称来查找相同名称的模板文件。在Rails中有两种方法来创建动态模板:使用叫做Builder的技术或是将Ruby代码嵌入到模板自身。REb:(Embedded Ruby)。在<%=以及%>中的内容被表现为Ruby代码并被执行,执行结果被转换为string。在<%以及%>被表示为没有输出的Ruby代表来执行。将%>替换为-%>来阻止输出插入空行。Rails使用了一些Ruby magic因而控制器对象的实便变量被注入到模板对象中,view模板可以访问被设置进控制器的实例变量,如他们自身的一样。Rails搜索app/views中与控制器相同名称的子目录,并且在该子目录中搜索action名称的文件。并通过ERb来来处理这些模板。 • ruby script/generate model category • ruby script/generate controller category • ruby script/generate scaffold category
Debug(question?) • 说明:Aptana下使用Debug需要安装这里的包 • http://rubyforge.org/frs/?group_id=1900 (for base, debug) • Install as http://blog.sina.com.cn/s/blog_44c07fb301008c6o.html • http://rubyforge.org/frs/?group_id=3085 (for ide) • 方法(注意顺序): 安装base-win32.gem版,不要误安不带win32版,否则会带来问题 装debug.gem(v: 0.10.3) 装ide.gem(v: 0.4.5, 发现0.4.8, 0.4.9装不上,不知咋回事) 在线不行就下下来安装 • 在aptana中运行需要ide>=0.4.5的 • Aptana下的配置:Debug模式下设置断点,就可以运行、调试
Ruby syntax • Comments: Single line: # Multiple line: =bend comment content =end • @-实例变量; • :-符号标识符
Questions • Performance • Server changed, use with Apache? • File upload/download/persistence • DB master/slave back-up • Logging… log4r • Mail • User constraints(Registered or not) • Multiple version browser supported
Server & Deploy • WEBrick/Mongrel(http://mongrel.rubyforge.org/ )
Resoures • Stetp by step: http://blog.csdn.net/infowain/archive/2007/03/26/1541548.aspx