每天一剂Rails良药知识库


未分类文章

Rails宝典之第八式: layout与content_for

如果我们想根据模板页面更改局部layout,使用content_for即可。 content_for允许模板页面代码放到layout中的任何位置。 比如我们的Rails程序不同的页面有不同的css样式,我们可以在layout里留出位置: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http ...
hideto 评论 (1) 有 2212 人浏览 2011-05-26

Rails宝典之第七式: layout详解

这次的视频很有用,详细解释了layout的用法 一般来说layout有如下五种: gobal layout,controller layout,shared layout,dynamic layout,action layout 假设我们有一个views/projects/index.rhtml页面: <h2>Projects</h2> <ul> <% ...
hideto 评论 (1) 有 2062 人浏览 2011-05-26

Rails宝典之第六式: Symbol to Proc

这次来介绍ActiveSupport里对Symbol的扩展,我们先来看active_support/core_ext/symbol.rb文件: class Symbol # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples: # # # The same as peo ...
hideto 评论 (0) 有 1561 人浏览 2011-05-26

Rails宝典之第五式: 使用with_scope

这次来介绍with_scope方法的使用。 继续前面的例子,我们希望只取得complete为false的前20条数据,我们可以给find_incomplete方法添加一个Hash参数,然后使用with_scope将 额外的参数附加到我们的查询方法里: class Task < ActiveRecord::Base belongs_to :project def self.find_inco ...
hideto 评论 (0) 有 1373 人浏览 2011-05-26

Rails宝典之第四式: 将查询移位Model

沿着Rails宝典之第三式: 通过关联做查询的脚步,我们可以进一步简化代码: class Task < ActiveRecord::Base belongs_to :project def self.find_incomplete find_all_by_complete(false, : order => 'created_at DESC') end end class Proje ...
hideto 评论 (0) 有 1383 人浏览 2011-05-26

Rails宝典之第三式: 通过关联做查询

Rails宝典之第三式: 通过关联做查询 我们来看一个has_many关联的例子: class Project < ActiveRecord::Base has_many :tasks end class Task < ActiveRecord::Base belongs_to :project end class ProjectsController < Applicatio ...
hideto 评论 (0) 有 1490 人浏览 2011-05-26

Rails宝典之第二式: 动态find_by方法

Rails宝典之第二式: 动态find_by方法 忘了声明了,这个系列主要是Rails入门教学。 今天Rails宝典教大家的是动态find_by方法,我们先看一段代码: class TasksController < ApplicationController def incomplete @tasks = Task.find(:all, :conditions => ['comp ...
hideto 评论 (0) 有 1682 人浏览 2011-05-26

Rails宝典之第一式: 实例变量做查询缓存?

前段时间对Rails的跟进有点懈怠,因为公司让我做Spring的内部培训,便抽空回归Java,看了下字符集,字节码,Annotation, JavaConfig,JavaScript,Perl,花生壳等等乱七八糟的东西,差点把心收不回来准备去搞C#.net了。 每天一剂Rails良药要开工了,顺便把《The Ruby Way》eMule下来了,再写个“每天一条Ruby小道”怎么样? 前段时间订阅 ...
hideto 评论 (0) 有 2083 人浏览 2011-05-26

ActionController::Resources + ActiveResource = REST

从Rails的svn资源库下载最新的Rails,我们会发现多了个activeresource包 从此Rails核心模块变为: ActiveRecord、ActionPack、ActionWebService、AcionMailer、ActiveResource、ActiveSupport和Railties 这里有几个问题: 一,ActionController里的resources.rb文件与A ...
hideto 评论 (1) 有 1993 人浏览 2011-05-26

Rails源码研究之ActionView:七,capture_helper

Struts有Tiles,WebWork可以用sitemesh,而Rails呢?有Capture! 请看活生生的例子先: 例子1: # layout.rhtml: <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> & ...
hideto 评论 (0) 有 1056 人浏览 2011-05-26

Rails源码研究之ActionView:六,scriptaculous_helper

scriptaculous_helper主要是对scriptaculous的controls和effects相关方法调用的封装 require File.dirname(__FILE__) + '/javascript_helper' module ActionView module Helpers module ScriptaculousHelper unless const_defined? ...
hideto 评论 (0) 有 1019 人浏览 2011-05-26

Rails源码研究之ActionView:五,prototype_helper

Rails的Ajax是依赖于prototype库的,我们来看看ActionView对prototype的一些方法调用的封装 源文件为prototype_helper.rb,其中包括RJS的update_page调用的JavaScriptGenerator类的定义: 1,link_to_remote是简单的异步url请求 def link_to_remote(name, options = {}, ...
hideto 评论 (0) 有 1525 人浏览 2011-05-26

Rails源码研究之ActionView:四,javascript_helper

跟模板中JavaScript相关的helper方法定义文件有javascript_helper.rb/prototype_helper.rb/scriptaculous_helper.rb 其中javascript_helper与基本的JavaScript功能有关,prototype_helper与Ajax有关,而scriptaculous_helper与controls和visual effect ...
hideto 评论 (0) 有 1056 人浏览 2011-05-26

Rails源码研究之ActionView:三,form_helper

ActionView还带有许多helpers,让我们开发起来更快速更顺手,让我们来看看form中常用的一些helper方法 form_helper.rb: module ActionView module Helpers module FormHelper def form_for(object_name, *args, &proc) raise ArgumentError, " ...
hideto 评论 (0) 有 1959 人浏览 2011-05-26

Rails源码研究之ActionView:二,partials

partials是Rails模板重用的一项重要技术,让我们来读读partials.rb源码文件: module ActionView module Partials def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns = nil) path, partial_name = partial_pi ...
hideto 评论 (0) 有 894 人浏览 2011-05-26

知识库信息

最新评论

不能适应超过三层的的override,比如我有A,B,C三个模板,B在A的基础上添加自己的东西,C在B ...
mingliangfeng 评论了 Rails宝典之第八式: layout与content_for
讲的很清楚,赞
lixinso 评论了 ActionController::Resources + ActiveReso ...
这个插件的下载地址:https://github.com/rails/ssl_requirement
kaogua 评论了 每天一剂Rails良药之ssl_requirement
能评论吗???
refar 评论了 Rails宝典之第五十一式: will_paginate
<%= error_message_on "post", "ti ...
fcp6316 评论了 Rails宝典之第六十五式: Stopping spam
rake db:fixtures:load # Load fixtures into the cur ...
xu_ch 评论了 Rails宝典八十一式:Rails2.0之Fixtures尝 ...
[/b][i][/i][u][/u]引用[color=red][/color][size=medium ...
linjie_830914 评论了 Rails源码研究之ActionController:二,ro ...
并行工程环境的面向成本设计
libiun 评论了 Rails宝典八十五式:YAML配置文件
...
xu_ch 评论了 Rails宝典之第五十七式: Select or Create
你老好了,找的就是他了
xu_ch 评论了 Rails宝典之第七式: layout详解
Global site tag (gtag.js) - Google Analytics