Rails框架技术讲座:如何理解和使用帮助模块Calendar_Helper

Posted by cnrails Wed, 10 May 2006 18:04:00 GMT

Rails框架技术讲座:如何理解和使用帮助模块Calendar_Helper

目录

 (一)系统环境:

  1. Ruby 语言>1.8.2版本,安装方法请点击这里Ruby1.8.2 或者 点击这里Ruby1.8.4
  2. Rails 框架>1.1.0版本
  3. Windows XP 或者 Windows 2000操作系统
  4. 需要一个浏览器,如FireFox1.5.0.1
  5. Notepad2 开发编辑工具,安装方法请单击这里

 (二)前提条件:

  1. 我们的工作目录为d:\works_rails。
  2. 你的电脑一定要连接互联网。

 (三)目的:

  1. 在Rails框架应用软件中,如何理解和使用帮助模块calendar_helper。这里既没有说明如何使用插件Calendar_Helper以及如何把它与数据捆绑起来,也没有说明如何使用该插件Calendar_Helper的软件款式。
  2. 我们创建项目的完整代码 calendar_helper.zip

 (四)解决方案:

  1. 创建一个名称为 calendar_helper 项目,其命令如下:
    rails calendar_helper
  2. 创建一个控制器类文件,其方法如下:
    cd calendar_helper
    notepad2 app\controllers\calendar_controller.rb

  3. 这是帮助模块Calendar_Helper的代码,我增加了年代显示代码:
    notepad2 app\helpers\calendar_helper.rb


  4. 创建控制器CalendarController类的页面index.rhtml,其方法如下:
    mkdir app\views\calendar
    notepad2 app\views\calendar\index.rhtml


  5. 启动网络服务器WEBrick,在DOS-Shell中输入如下命令:
    ruby script\server
  6. 你可以通过打开浏览器输入如下地址,看到日历显示。
    http://localhost:3000/calendar/index

    http://localhost:3000/calendar/index?month=3&year=1993


 (四)视听教学:



 (五)必须注意的问题:

  • 控制器CalendarController类是Rails框架保护类名。你无法通过ruby script\generate controller calendar index产生该类。

 (六)参考资料:

  1. 有关Ruby语言日期API:
    chrome://devboi_ruby_on_rails/content/_docs/ruby_stdlib/libdoc/date/rdoc/classes/Date.html
    相关资料在"http://groups.google.com/group/cnrails"
  2. 有关插件Calendar_Helper的使用说明:
    http://www.jvoorhis.com/pages/calendar-helper
  3. 有关插件Calendar_Helper的技术说明:
    http://wiki.rubyonrails.org/rails/pages/CalendarHelper





________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags ,  | no comments | no trackbacks

Rails框架代码索引:模型属性权限(Permissions)

Posted by cnruby Tue, 09 May 2006 20:39:00 GMT

Rails框架代码索引:模型属性权限(Permissions)


attr_accessor :name, :date, :location

attr_reader # create reader only

attr_writer # create writer only

attr_accessor # create reader and writer

attr_accessible




________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags ,

Rails框架代码索引:模型数据有效性(Validations)

Posted by cnruby Tue, 09 May 2006 20:10:00 GMT

Validations

validates_presence_of :firstname, :lastname     # must be filled out

validates_length_of :password,
:minimum => 8 # more than 8 characters
:maximum => 16 # shorter than 16 characters
:in => 8..16 # between 8 and 16 characters
:too_short => 'way too short'
:too_long => 'way to long'

validates_acceptance_of :eula # Must accept a condition
:accept => 'Y' # default: 1 (ideal for a checkbox)

validates_confirmation_of :password
# the fields password and password_confirmation must match

validates_uniqueness_of :user_name # user_name has to be unique
:scope => 'account_id' # Condition:
# account_id = user.account_id

validates_format_of :email # field must match a regular expression
:with => /^(+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

validates_numericality_of :value # value is numeric
:only_integer => true
:allow_nil => true

validates_inclusion_in :gender, # value is in enumeration
:in => %w( m, f )

validates_exclusion_of :age # value is not in Enumeration
:in => 13..19 # don't want any teenagers

validates_associated :relation
# validates that the associated object is valid




________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in  | Tags ,

Rails: Content-only caching for Rails

Posted by cnrails Sun, 07 May 2006 10:08:00 GMT

http://blog.codahale.com/2006/04/10/content-only-caching-for-rails/


________________________________________________________________ 您只要点击下面图标,就可以把本文加入到您喜欢的公共收藏库中去。
del.icio.us Digg | FURL | Yahoo! My Web 2.0 | Reddit | Blinklist | Fark

Posted in

Older Posts

Older Posts: 1 ... 89 90 91 92 93 ... 110