Rails框架技术讲座:分页技术插件will_paginate

Posted by cnruby Thu, 12 Jul 2007 19:04:00 GMT

Rails框架技术讲座:分页技术插件will_paginate


  Rails框架的分页技术将在下一个版本有比较大的变化。所谓分页技术就是将数据记录在多个页面显示。而现有Pagination系统已经从当前Rails框架开发分枝代码库被删除了(Changeset 6992)。未来什么是Rails框架的分页技术呢?看看插件will_paginate


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

Posted in  | Tags , , , , ,

Rails框架技术讲座:集成RFPDF软件包到中文Rails框架应用软件

Posted by cnruby Tue, 10 Jul 2007 18:59:00 GMT

集成RFPDF软件包到中文Rails框架应用软件

  生成动态的pdf文件是企业应用软件的一个必备的功能。虽然在Rails框架应用软件中实现这一功能方法是相对地丰富[ 1 ]。但是对于中文支持的软件却很有限,而相关的技术文档更是稀少。本文将说明如何在Rails框架应用软件中动态地生成的中文pdf文件及其如何有效地集成软件包RFPDF到Rails框架应用软件。我们将分两部分说明这些内容。这个问题常常使得我们伤透脑筋,相信本文能够给你带来愉快的心情。

详细内容请看这里
PDF文件可以下载(需要注册)。



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

Posted in  | Tags , , ,

Rails框架技术讲座:基于RMagic使用插件attachment_fu

Posted by cnruby Mon, 25 Jun 2007 21:24:00 GMT

Rails框架技术讲座:基于RMagic使用插件attachment_fu

目录
 (一)系统环境:

  1. Ruby 语言 1.8.4版本, 点击这里Ruby1.8.4。要想安装多个Ruby语言运行环境请看这里
  2. Rails 框架 1.2.1版本,安装方法请看这里,最简单方法是第一种方法即可。
  3. Windows XP 或者 Windows 2000操作系统 或者 Linux操作系统
  4. 需要一个浏览器,如FireFox1.5.0.1以上版本。
  5. 开发编辑工具 Notepad2 ,安装方法请单击这里,复制一个notepad2.exe,并且更名为vi.exe。
  6. 在Windows XP上安装Linux核心命令,点击这里
  7. 如何在Windows Console下使用命令svn(下载软件),点击这里

 (二)前提条件:

  1. 在本机Winodw操作系统上,我们的工作目录为d:\works_rails。
  2. 你的电脑必须在线。
  3. 安装软件ImageMagic和RMagic:
    wget http://rubyforge.org/frs/download.php/15132/RMagick-1.14.1_IM-6.3.0-7-Q8.zip
    unzip RMagick-1.14.1_IM-6.3.0-7-Q8.zip
    cd RMagick-1.14.1_IM-6.3.0-7-Q8
    gem install rmagick-1.14.1-win32.gem -l
    start ImageMagick-6.3.0-7-Q8-windows-dll.exe

 (三)目的:

  1. 在软件ImageMagick和及其Ruby语言软件接口RMagick基础上,如何使用Rails框架的图片上载插件attachment_fu,该插件使用方便和集成简单。相关说明请看这里
  2. 本讲座的完整代码请您在Google Code Hosting上查看
    http://cnruby.googlecode.com/svn/trunk/rails-projects/use_attachment_fu_rmagic
    或者下载:
    svn co http://cnruby.googlecode.com/svn/trunk/rails-projects/hobo_view01

 (四)解决方案:

  1. 创建一个Rails框架应用软件,安装图片上载插件attachment_fu
    rails use_attachment_fu_rmagic
    cd use_attachment_fu_rmagic
    ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/
  2. 根据Rails框架自动代码生成技术,生成控制器Thumb及其相关代码,该命令与命令scaffold不同的是,它不需要事先把数据库表生成好。这是基于REST技术的代码生成工具。
    ruby script\generate scaffold_resource Thumb
  3. 根据Rails框架数据库迁移技术,编写迁移代码:
    vi db\migrate\001_create_thumbs.rb
      def self.up
        create_table :thumbs do |t|
          t.column :parent_id,  :integer
          t.column :content_type, :string
          t.column :filename, :string   
          t.column :thumbnail, :string
          t.column :size, :integer
          t.column :width, :integer
          t.column :height, :integer
        end
      end
  4. 修改数据库配置文件并且执行数据库迁移命令
    vi config\database.yml
      development:
        adapter: sqlite3
        database: db/attachment_fu.db

      test:
        development
       
      production:
        development
    rake db:migrate
  5. 修改数据库模型代码,基本上固定的。
    vi app\models\thumb.rb
      has_attachment :content_type => :image,
                     :storage => :file_system,
                     :max_size => 500.kilobytes,
                     :resize_to => '320x200',
                     :thumbnails => { :thumb => '100x100' }

      validates_as_attachment
  6. 修改控制器代码,根据需要而定,这是一个实例代码。
    vi app\controllers\thumbs_controller.rb
      def index
        @thumbs = Thumb.find(:all, :conditions=>["thumbnail is null"])

        respond_to do |format|
          format.html # index.rhtml
          format.xml  { render :xml => @thumbs.to_xml }
        end
      end
  7. 修改页面两个页面,这是该插件典型的代码。
    vi app\views\thumbs\new.rhtml
      <% form_for(:thumb, :url => thumbs_path,
                            :html => { :multipart => true }) do |f| -%>
        <p>
          <label for="thumb">Upload A Image:</label>
          <%= f.file_field :uploaded_data %>
        </p>
        <p>
          <%= submit_tag 'Create' %>
        </p>
      <% end -%>

    vi app\views\thumbs\index.rhtml
      <h1>Most Wanted</h1>
      <% for t in @thumbs -%>
        <%= link_to image_tag(thumb.public_filename(:t)), thumb.public_filename %>
      <% end -%>
  8. 启动浏览器并且输入网址:
    ruby script/server
    http://localhost:3000/thumbs

 (五)视听教学:



 (六)必须注意的问题:



 (七)参考资料:

  1. Rails框架插件:文件上传大全

 (八)命令清单:

rails use_attachment_fu_rmagic
ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/

ruby script\generate scaffold_resource Thumb

vi db\migrate\001_create_thumbs.rb
def self.up
create_table :thumbs do |t|
t.column :parent_id, :integer
t.column :content_type, :string
t.column :filename, :string
t.column :thumbnail, :string
t.column :size, :integer
t.column :width, :integer
t.column :height, :integer
end
end
vi config\database.yml
development:
adapter: sqlite3
database: db/attachment_fu.db

test:
development

production:
development
rake db:migrate

vi app\models\thumb.rb
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '320x200',
:thumbnails => { :thumb => '100x100' }

validates_as_attachment

vi app\controllers\thumbs_controller.rb
def index
@thumbs = Thumb.find(:all, :conditions=>["thumbnail is null"])

respond_to do |format|
format.html # index.rhtml
format.xml { render :xml => @thumbs.to_xml }
end
end


vi app\views\thumbs\new.rhtml
<% form_for(:thumb, :url => thumbs_path,
:html => { :multipart => true }) do |f| -%>
<p>
<label for="thumb">Upload A Image:</label>
<%= f.file_field :uploaded_data %>
</p>
<p>
<%= submit_tag 'Create' %>
</p>
<% end -%>

vi app\views\thumbs\index.rhtml
<h1>Most Wanted</h1>
<% for t in @thumbs -%>
<%= link_to image_tag(thumb.public_filename(:t)), thumb.public_filename %>
<% end -%>

ruby script/server
http://localhost:3000/thumbs



 (九)下载文件pdf:

  1. 下载



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

Posted in  | Tags , , , , ,

Rails框架技术讲座:基于网络服务器使用本地化插件gibberish

Posted by cnruby Mon, 21 May 2007 09:47:00 GMT

Rails框架技术讲座:基于网络服务器使用本地化插件gibberish

目录
 (一)系统环境:

  1. Ruby 语言 1.8.4版本, 点击这里Ruby1.8.4。要想安装多个Ruby语言运行环境请看这里
  2. Rails 框架 1.2.1版本,安装方法请看这里,最简单方法是第一种方法即可。
  3. Windows XP 或者 Windows 2000操作系统 或者 Linux操作系统
  4. 需要一个浏览器,如FireFox1.5.0.1以上版本。
  5. 开发编辑工具 Notepad2 ,安装方法请单击这里,复制一个notepad2.exe,并且更名为vi.exe。
  6. 在Windows XP上安装Linux核心命令,点击这里
  7. 如何在Windows Console下使用命令svn(下载软件),点击这里

 (二)前提条件:

  1. 在本机Winodw操作系统上,我们的工作目录为d:\works_rails。
  2. 你的电脑必须在线。

 (三)目的:

  1. 基于网络服务器在Rails框架应用软件中使用本地化插件gibberish。只要有了它,Rails框架的本地化就十分地方便。使用该插件一次性工作是安装该插件和设定本地化语言;多次性工作是修改本地化文件和页面文件。

 (四)解决方案:

  1. 创建Rails框架应用软件use_gibberish
    rails use_gibberish
    cd use_gibberish
  2. 安装插件gibberish到我们的软件中
    ruby script/plugin install svn://errtheblog.com/svn/plugins/gibberish
  3. 设定Rails框架软件的本地化语言
    vi config\environment.rb
    把下面的代码放在该文件最后一行
    Gibberish.current_language = :zh
  4. 创建本地化文件目录和本地化文件
    mkdir lang
    vi lang/zh.yml
    下面的内容是文件zh.yml的代码,该文件使用UTF-8编码格式
      # UTF-8
      hello: "您好!"
      hello_name: "{name}, 您好!"
  5. 创建一个控制器和一个页面
    ruby script/generate controller Admin index
  6. 使用本地化文件编辑页面文件
    vi app/views/admin/index.rhtml
    下面的内容是文件index.rhtml的代码,该文件使用UTF-8编码格式
      <!-- UTF-8 -->
      <h1><%= "No TRANSLATION: hello"[:hello] %></h1>
      <h1><%= "No TRANSLATION: hello_name"[:hello_name, "温总理"] %></h1>
  7. 打开网络服务器以及浏览器,查看我们的本地化结果
    ruby script/server
    http://localhost:3000/admin

 (五)视听教学:



 (六)必须注意的问题:

  • 如果文件lang/zh.yml没有任何内容,可能会出现下面错误信息提示:
    vendor/plugins/gibberish/lib/gibberish/localize.rb:56:in `load_languages!': undefined method `symbolize_keys' for false:FalseClass (NoMethodError)

 (七)参考资料:



 (八)命令清单:

rails use_gibberish
cd use_gibberish

ruby script/plugin install svn://errtheblog.com/svn/plugins/gibberish

vi config\environment.rb
# Include your application configuration below
Gibberish.current_language = :zh

mkdir lang
vi lang/zh.yml
# UTF-8
hello: "您好!"
hello_name: "{name}, 您好!"

ruby script/generate controller Admin index

vi app/views/admin/index.rhtml
<!-- UTF-8 -->
<h1><%= "No TRANSLATION: hello"[:hello] %></h1>
<h1><%= "No TRANSLATION: hello_name"[:hello_name, "温总理"] %></h1>

ruby script/server
http://localhost:3000/admin

 (九)下载文件pdf:




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

Posted in  | Tags , , ,

Older Posts

Older Posts: 1 2 3 4 ... 27