Rails on Campus: 华农版 - Session #3

The excellent students at South China Agriculture University

Rails on Campus Roundup / Rails on Campus 大聚集


Last Saturday we concluded the Rails on Campus: 华农版 (SCAU) program with session #3. We wish to thank Dean Song, Professor Sun, and all the students who took the time to attend. We really appreciate working with such amazing students, and we were very happy to be able to come to your school.

上周六我们在华农顺利地进行了Rails on Campus 第三期活动。在此非常感谢宋主任,孙教授以及所有到场的学生。 真的很难得可以跟这么多这么优秀的学生一起分享和学习, 我们也很高兴能够来到你们学校。

And special congratulations to 欧振聪 Clarence Au (@onionou) the winner of our coding competition!

同时,我们在这里恭喜欧振聪同学@onionou赢了我们组织的这场代码比赛!

Over the course of 3 sessions, we've introduced the students to the basics of Rails, and hopefully they will be able to keep learning about Rails and ruby. To recap, here's what we've gone over:

通过这三次活动,我们向学生们分享了一些Rails的基本知识,希望他们可以在课余时间继续学习Rails和Ruby。概括一下,我们谈及的有以下方面的话题:

  • Getting the Rails environment - RailsInstaller.org, ruby-lang.org, SublimeText
  • Basic ruby syntax - messages.each {|m| puts m}, hash = {:key1=>'val1'}
  • Creating a new Rails app from scratch - rails new miniblog
  • Using scaffolding to get started quickly - rails generate scaffold message body:text
  • Creating associations between models - message: has_many :replies, reply: belongs_to :message
  • Using Rails view helpers to build forms - form_for [:message, Reply.new]
  • How to access the Rails session - session[:user_id]
  • Writing filters to manage authentication - before_filter :require_login
  • Custom routes for easy URLs - match 'login' => 'sessions#new'
  • Deploy your app to share with the world - heroku, DotCloud

The result of our work in class should be a working miniblog that you can share with your friends. Anyone can login, post messages, and reply to other users' messages.

在课堂上我们的练习任务是:创建一个miniblog, 通过这个miniblog 你可以跟朋友分享,每个人都可以登录, 发表信息同时也可以回复其他用户的信息。

We'd love to see you continue with your code. Add more features, improve the design, and put it up on heroku! Make sure to let us know via the Rails on Campus Weibo account.

我们非常希望你们可以继续写代码,让你的miniblog变得更好。 增加更多的功能,做更好的设计,然后放上heroku! 在微博上@RailsOnCampus 展示你的成果吧!

We also would appreciate any feedback, so please let us know how we can make the event go more smoothly next time, or if there's anything else we should cover. We hope to take this program to other universities in the area, and perhaps come back to SCAU for a second season next year.

欢迎对我们的活动提出您的宝贵意见! 这对我们很重要,希望我们下一次可以组织得更好,活动开展得更顺利。如果你有感兴趣的话题希望我们可以分享,欢迎给我们来信! 我们希望到广州更多的大学去分享,可以的话也希望明年回到华农分享更多有趣的话题!

Session #3 / 第三届


The third session in our program focused on completing the feature set to make our miniblog a full web application. Of course we needed a way for users to log in, so that we know who says what. To that end, we went over how to track user sessions, and how to use before_filters to manage users and make sure they log in when they need to.

在第三期我们会分享一些关于如何给我们的miniblog添加新功能新应用,使其变成一个更加完整的网络应用。 首先,我们必须想个办法让用户可以登录,这样我们才知道谁说了什么。然后我们也分享了如何去追踪用户及其发表的信息,以及如何使用before_filters 去管理用户,让他们在必要时进行登录。

Links:


Rails on Campus is a program started by Leon Du and Shaokun Wu, 2 ruby developers in Guangzhou, China. The idea is to build a good set of material for introduction courses that can be used to teach Rails on college campuses. College students are often not exposed to the latest development techniques, and are left to learn on the job. The goal of this program is to introduce students to the world of open source development frameworks to help prepare them for a good job.

Rails on Campus是由中国广州两位Ruby 开发者, Leon Du和伍少坤发起的。活动的初衷是为大学Rails的教学积淀一些有价值的学习材料。大学学生接触新技术的机会不十分多,而常常要上到工作岗位才开始学习。希望通过这次活动,可以为同学们带来更多开源的开发框架,以此为将来的好工作更好地准备自己。

Rails on Campus is sponsored by:

Rails on Campus的赞助团队有:

Posted by adevadeh 08 Dec 2011 at 04:08AM


Rails on Campus: 华农版

Last week we had our first Rails on Campus session at the South China Agriculture University (华南农业大学). We had an excellent turnout of 50 or 60 top-notch students. We were really impressed with their knowledge of web development in general, and their enthusiasm to learn new things.

上周末我们 Rails on Campus的第一次活动在华南农业大学展开了。大家反应热烈,有5,60个学生参加了我们的活动。同学们对知识的渴望给我们留下了深刻的印象,参加的同学基础知识也非常不错。

The first session focused on:

第一部分内容概要:

  • Setting up the Rails environment on your computer
  • Learning about the origin of Rails and ruby
  • Creating a new Rails app from the command line and adding a simple scaffold

We built a working web app as a demo in about 10 minutes, starting from rails new and finishing with a nice looking miniblog.

The only problem was the recent issues we've been having accessing rubygems from China. This made it very difficult for the students to get a Rails environment working on their own laptop. We hope to have a good solution for this problem before the next session.

For our next session, we'll continue to build on the same application by adding a reply feature.

Here are the links from session #1

这里有一些第一部分学习的相关链接:

---

Rails on Campus is a program started by Leon Du and Shaokun Wu, 2 ruby developers in Guangzhou, China. The idea is to build a good set of material for introduction courses that can be used to teach Rails on college campuses. In Guangzhou, and many other areas around the world, college students are often not exposed to newer technology, and are left to learn on the job. The goal of this program is to introduce students to a new world of open source development frameworks that are quite popular around the world. Not just Rails, but also things like Node.js or Python/Django.

Rails on Campus是由中国广州两位Ruby 开发者, Leon Du和Shaokun Wu 发起的。活动的初衷是为大学Rails的教学积淀一些有价值的学习材料。在广州,以及世界的一些其他的城市,大学学生接触新技术的机会不十分多,而常常要上到工作岗位才开始学习。希望通过这次活动,可以为同学们带来更多热门的开源的开发框架,以此为将来的好工作更好地准备自己。不单单是Rails,以后我们可能还会涉及到像 Node.js 或者 Python/Django 这样话题。

Rails on Campus is sponsored by:

Rails on Campus的赞助团队有:

+ gzruby - The Guangzhou Ruby Group http://gzruby.org/list
+ Kudelabs http://kudelabs.com
+ Beansmile http://beansmile.com

Posted by adevadeh 17 Nov 2011 at 03:15AM


Some Fun with Ruby Abstract Syntax Tree

For a while, I've been interested in gems that provide access to Abstract Syntax Tree (AST) representation of Ruby code, and potential possibilities they open. Just a couple days ago this interest was triggered again. The question that arose at the moment was:

  • say, we're facing somebody else's lengthy, sophisticated and rather unfamiliar code which we're planning to reuse. How do we find out where the code may be cache'ing results in instance variables - therefore, possibly, causing unplanned and undesired side effects?

Perhaps, we could convert the given piece of Ruby code into AST and then list all lines that correspond to instance variable assignment nodes... This felt like an interesting exercise so I ended up writing a little code snippet for that.

A few other possible AST uses, I thought, could be:

  • listing all methods defined in a specific file;
  • listing all method calls in a given class or method (e.g. to figure out external dependencies for refactoring or unit-testing purposes);
  • listing class variable assignments.

So, the initial script evolved into a more generic parsetree_locator.rb utility (note: requires 'ruby-parser' gem; also, only tried it on MRI Ruby 1.9).

Let me present a few examples of how the utility works.

 

Examples

Say, we have the following Ruby code in 'example.rb' file:

module M
  class C
    def meth
      @a = 2
      b = 3
    end

    def call_meth
      meth
    end

    def another_meth
      @n = 95
      call_meth
    end
  end
end

1) List all instance variable assignments - "iasgn" AST nodes:

$ ruby parsetree_locator.rb "iasgn" "example.rb"

Result:

Line nr | Module, class, method                              | Code
4:      | module M, class C#meth                             | @a = 2
13:     | module M, class C#another_meth                     | @n = 95

2) List all defined instance methods - "defn" AST nodes:

$ ruby parsetree_locator.rb "defn" example.rb

Result:

Line nr | Module, class, method                              | Code
3:      | module M, class C                                  | def meth
8:      | module M, class C                                  | def call_meth
12:     | module M, class C                                  | def another_meth

3) List all method calls - "call" nodes:

$ ruby parsetree_locator.rb "call" example.rb

Result:

Line nr | Module, class, method                              | Code
10:     | module M, class C#call_meth                        | end
15:     | module M, class C#another_meth                     | end

-- seems like the line numbers are slightly off in this case. The author of 'ruby_parser' gem mentions that it may happen; the results seem reasonable most of the time, though.

Hope that somebody else finds this utility useful as well, enjoy! parsetree_locator on GitHub

Posted by Jevgenij Solovjov 24 Oct 2011 at 07:52AM


Rails on Campus Wrap-up

After 2 great sessions of Rails on Campus: 华工版, we'd like to thank everyone who took part in helping to plan and organize this event. We learned a lot from the experience, and we hope the attendees did as well. We plan to take our materials from this first run, refactor, and put on a better program next year!

Before we close out for the year though, I wanted to go over what you can do to continue learning on your own.

Install Rails

http://railsinstaller.org - Download and run the installer. It will install everything you need to get started writing your own Rails apps (ruby, git, rubygems, rails).

Get the demo code

http://github.com/kudelabs/roc-demo2 - Clone the project and get it running on your computer .

git clone git://github.com/kudelabs/roc-demo2.git 
cd roc-demo2
rake db:migrate
rails s
open http://localhost:3000

Write some code

http://notepad-plus-plus.org/ - You can use any text editor to write code, but its much easier in a real code editor like Notepad++. It's free, give it a try.
http://http://guides.rubyonrails.org/getting_started.html - Take a look at the Rails Guides for more in-depth tutorials
http://asciicasts.com - Another great resource with tons of tips and information

Share with the world

http://heroku.com - A free service to host your amazing Rails app! It works right from the command line and in 5 minutes you have a public site that you can show to anyone.

Just Do It

So now you have no excuse. You have the tools, you have the code, you have the servers. Go write an inspiring app and make us proud!

Posted by adevadeh 09 Jun 2011 at 09:24AM


Rails on Campus: 华工版 - Session 1

The first Rails on Campus session went very well last saturday, with around 50 budding rubyists in attendance. We went over the history and purpose of Ruby and then Rails, and then did a live demo of: Build your own miniblog in 20 min.

Rails on Campus 上周六的活动开展得非常顺利,大约50名对Ruby感兴趣的同学参加了此次活动。我们对Ruby 和Rails 的历史以及意义都作了简单的阐述,并且现场做了一个迷你演示:怎么样在20分钟内建一个属于你微博。 :)

Since we didn't have wifi at the venue, it was hard to show all the links and make sure students could write them all down, so here's a list of important links:

由于我们现场没有wifi设备,很难向大家展示所有的链接,同时也考虑到可能一些同学也来不及记下来。 大家不妨看看以下关键的链接,可以更好地理解我们分享的内容:

Thanks to everyone involved, and to all the attendees. We all look forward to working together again next week!

非常感谢到场的每位同学以及工作人员,让我们一起期待下一次的活动!

Posted by adevadeh 09 May 2011 at 11:05AM


Automated testing tools:Selenium & Watir

When should use automation?

What is advantageous for automated testing? When should one decide to automate test cases?

For the short term project,manual testing may be more effective. If an application has a very tight deadline, there is currently no test automation available,then manual testing is the best solution.

However, automation has specific advantages for improving the long-term efficiency of a software team’s testing processes.As we can save the time special for the regression test.What is more,it is trivial for the tester if repeat the same test case.

Selenium

  • Start from Selenium IDE:
  • Selenium IDE is a plug-in for FireFox,and isn't available for other browser.

    It provides an easy-to-use interface for developing and running individual test cases or entire test suites.

    Selenium-IDE has a recording feature,then can export the code in several kinds of language.

    Right now,give a example for how to use it.

    Suppose we want to login Gmail:

    Open the FireFox browser,click the "Tools" tab,then you can see the "Selenium IDE" is in the list,click it and will pop up a window as following:

    Selenium IDE 1.0.7

    Then back to the FireFox browser,open google home page and click the "Gmail" link,then fill info and press "Sign in" button.

    Turn to the Selenium IDE again,all the actions are recorded,see the following screenshot:

    Record_login_gmail

    Click the red round button in the upper right corner to stop the record.The browser will execute the action what you did just now when hit the green triangle button.

  • Selenium RC:
  • Selenium IDE can only run the test in FireFox.Obviously,this is not enough.So we must mention Selenium RC.

    We can export the code and apply the test in others browser through Selenium RC.

    It is simple to export the code in Selenium IDE,view the picture:

    export_code

    Usually,the exported code isn't perfect.Luckily,Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic.

    It provides an API and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. This ability to use Selenium-RC with a high-level programming language to develop test cases also allows the automated testing to be integrated with a project’s automated build environment.

  • Selenium Commands:
  • Contain three parts:Command,Target and Value

    Just give the simple explanation here

    Command:What you want to do for the browser.Such as,"click" a link,"fill" the textarea and so on.

    Target:Tell the browser which element you want to execute the command.

    Value:The value that you want to fill or expect.Sometimes it is blank.It depends what kind of command is used.

    Watir:

  • Introdution
  • Watir is an open-source library for automating web browsers.

    It is a family of Ruby libraries but it supports your app no matter what technology it is developed in.

    It drives browsers the same way people do. Watir also checks results, such as whether expected text appears on the page.

    Watir supports multiple browsers on different platforms.

    Windows 2000/2003/XP/Vista/7 : IE6,IE7,IE8 and FireFox

    Mac:FireFox and Safari

    Ubuntu:FireFox

  • Install Watir
  • Install watir on different system is not the same.I just describe how to install it on Mac for Safari.

    You have to install Ruby first,we recommend using Ruby 1.8.6 on all platforms.

    The type the following commands in Terminal:

    $ sudo gem update --system
    
    $ sudo gem install rb-appscript
    
    $ sudo gem install safariwatir
    

    A moment later,the following info appears and indicates the Safariwatir is installed successfully.

    $ sudo gem install safariwatir
    Successfully installed safariwatir-0.3.7
    1 gem installed
    Installing ri documentation for safariwatir-0.3.7...
    Installing RDoc documentation for safariwatir-0.3.7...
    
  • Use Safariwatir step by step:
  • We also choose the Login Gmail as example so that it is easy to compare what is different between Watir and Selenium.

    Open your Terminal and start irb.

    $ irb
    

    Before going to the Google,you have to let Ruby know you want to use SafariWatir,so please type:

    irb(main):001:0> require "rubygems"
    => true
    irb(main):002:0> require "safariwatir"
    => true
    

    Then start the browser

    irb(main):003:0> safari=Watir::Sfari.new
    => #, @app=app("/Applications/Safari.app"), @document=app("/Applications/Safari.app").documents[1]>>
    

    Go to Google:

    irb(main):004:0> safari.goto "http://www.google.com"
    => nil
    

    Click the "Gmail" link in the upper left corner:

    irb(main):005:0> safari.link(:text,"Gmail").click
    => nil
    

    After flowing to the login page,you can fill personal info and hit "Sign in" button to login.

    To do this, we have to find out some attribute of text field, like id or name, so Safariwatir can find it on the page. We will use Firebug for the first time.

    irb(main):006:0> safari.text_field(:id,"Email").set("ruby@gmail.com")
    => :missing_value
    irb(main):007:0> safari.text_field(:id,"Passwd").set("ruby")
    => :missing_value
    irb(main):008:0> safari.button(:value,"Sign in").click
    => nil
    

    If the username and password are correct,you should login successfully.

    Compare

  • Convenience
  • Selenium IED can record the acitons and export the code,so can save lots of time for the script developer.Watir doesn't have this tools,all the codes have to be typed by hand.

  • On different system
  • Mac OS X:

    Developers still need to strive for Safariwatir and Firewatir,as lots of commands that works fine in Windows cannot apply in Mac.What is more,performance isn’t stable.

    However,Selenium can resolve all the issue that watir is unable to deal with.

    So watir is not good as Selenium on Mac.

    Windows:

    Use selenium to test IE is not the same as FireFox in Mac.Especially for the locator,running the script will be very slow if the locator isn't suitable.

    Originally developed watir is to apply on IE.Until now,it is perfect.

    Posted by 钟宇平 10 Jun 2010 at 09:29AM


    来自asciicasts.com文本形式的Rails动态短片

    这对于我们早期贴出的Rails动态短片是一个很好的更新。


    来自英国的Rails程序员Eifion Bedford正在收集Ryan Bates系列的文本形式的免费动态短片。这意味着他是精心抄写Ryan的著作,整理截图,您可以学习这些代码示例并复制和粘贴它们。这是一个很好的学习这些材料的途径,尤其对于非英语母语的人来说。他所称的ASCII Casts,是一个巨大的免费学习Ruby and Rails的额外材料。我推荐安全系列性能提示。感谢Eifon努力为我们描绘生动的网页开发世界。

    Posted by 钟宇平 25 Feb 2009 at 04:11PM


    Railscasts in text form - ASCIIcasts.com

    This is an update to my earlier post about Rails Screencasts .


    British Rails developer Eifion Bedford is putting together a collection of Ryan Bates’ free Railscasts series in a text form. This means he is painstakingly transcribing Ryan’s words, putting together screenshots that you can learn from, and code examples that you can copy and paste. This is a great way to consume the material, especially if English is not your first language. The ASCII Casts, as he is calling them, are a great addition to the growing volume of free learning material for Ruby and Rails. I recommend the security series and the performance tips. Thanks to Eifon and his efforts to illuminate the wild world of web development!

    Posted by adevadeh 24 Feb 2009 at 05:42PM


    railscasts(Rails短片)帮助你成为ruby高手

    click here to read the English vesion of this article
    点击这里浏览本篇文章的英文版

    随着Rails越来越受欢迎,用于学习Rails的资源也越来越多。其中最好的一种学习方式就是看那些关于Ruby和Rails的视频短片(ScreenCasts)。这些短片让你在听讲授者解释概念的同时可以看到相应的代码。通常,这些短片对应一些经典的教材,但是通过这种视频短片的方式,这些内容变得更容易理解,你可以更加直观的感受到那些枯燥的概念背后的真正的含义。

    首先,有一些优秀而且免费的由Ryan Bates讲授的关于Rails的短片可以从这里下载:railscasts.com。他们短小精悍,常常重点突出某一个新的特征。你可以用iTunes把这些短片自动下载到你的电脑里(但是这在中国大陆行不通,因为Feedburner被拦截了),或者你可以直接从网站下载。这些短片里面有一组是专门讲述Rails 2.1 的新特征的,很值得一看。

    其次, Screencast之父, @topfunky a.k.a Geoffrey Grosenbach 也已经整理好了一组出色的关于Rails的培训教材,并把它们放在了peepcode.com上。这些教材是收费的,但是并不算贵,每个视频只要9美元即可(考虑到美国的消费水平,的确是相当便宜了)。这些教材很优秀,含金量很高,物超所值。我们已经学习过这些短片,它们帮助我们跟上了新版本rails发展的速度,此外我们也从那里下载了一些关于Rails的PDF书籍。我们极力推荐从这些教材入手学习Rails。

    Rails运行在Ruby环境,我也找到了一些很好的关于如何使用Ruby编程的视频短片(ScreenCasts)。Dave Thomas of The Pragmatic Programmers(也就是Web开发敏捷之道(Agile Web Development with Rails)的作者)亲自在短片中讲授了Ruby对象模型,类继承和元编程(meta-programming)的基本概念。它们能够帮助你充分发挥Ruby的强大威力,并帮你建立理解Rails框架的基础知识背景。这些视频短片(ScreenCast)只要5美元一个(别误会,我可不是他们的推销员,如果他们付给我报酬的话,我倒是很乐意帮他们推销一下)。

    如果你真的对Rails和Ruby感兴趣,我强烈推荐你使用以上这些网络上的学习资源,当然你要需要下载相关的工具,并准备好开始写你自己的Rails代码。

    尽情享受Rails把,未来的Ruby黑客们!

    Posted by 张晓峰 16 Jun 2008 at 08:10PM



    >