每天一剂Rails良药知识库


最近更新文章

Rails宝典之第三十九式: 自定义field_error

我们先来看action_view/helpers/active_record_helper.rb里的一段代码: module ActionView class Base @@field_error_proc = Proc.new{ |html_tag, instance| "<div class=\"fieldWithErrors\">#{html_tag ...
hideto 评论 (0) 有 1107 人浏览 2011-05-26

Rails宝典之第三十八式: 多按钮表单

看看一个多按钮的表单的例子: <!-- projects/new.rhtml --> <% if params[:preview_button] %> <div id="preview"> <h2><%= @project.name %></h2> <% textilize @project.desc ...
hideto 评论 (0) 有 1393 人浏览 2011-05-26

Rails宝典之第三十七式: simple search form

看一个简单的search表单 <!-- projects/index.rhtml --> <% form_tag projects_path, :method => 'get' do %> <p> <% text_field_tag :search, parmas[:search] %> <% submit_tag "Searc ...
hideto 评论 (0) 有 956 人浏览 2011-05-26

Rails宝典之第三十六计: Subversion on Rails

作者教我们怎样将Rails项目导入到Subversion mkdir svn_setup cd svn_setup/ rails blab cd blab mv config/database.yml config/databse_example.yml rm -r log/* rm -r tmp/* 我们不想将log、tmp目录里的文件都提交到svn,因为这些目录里的文件不是源代码 cd ...
hideto 评论 (0) 有 1037 人浏览 2011-05-26

Rails宝典之第三十五式: 自定义REST动作

REST将我们的controller限制到7个actions(index/show/new/create/edit/update/desctroy) 这次我们就来看看怎样添加自定义的actions class TasksController < ApplicationController def idnex... def show... def new... def create... de ...
hideto 评论 (0) 有 1349 人浏览 2011-05-26

Rails宝典之第三十四式: Named Routes

这次的视频讲述的是命名路由,有点火星了: # routes.rb map.resources :projects map.task_archive 'tasks/:year/:month', :controller => 'tasks', :action => 'archive' map.home '', :controller => 'projects', :action =& ...
hideto 评论 (0) 有 1065 人浏览 2011-05-26

Rails宝典之第三十三式: make a plugin

续上式。 我们可以将Task类里的due_at_string这个虚拟属性的生成做成一个plugin: ruby script/generate plugin stringify_time 这将在vendor/plugins目录生成如下文件: vendor plugins stringify_time ---init.rb ---install.rb lib ----stringify_tim ...
hideto 评论 (0) 有 887 人浏览 2011-05-26

Rails宝典之第三十二式: text_field time

一般编辑时间时我们使用datetime_select: <%= f.datetime_select :due_at %> 如果我们希望用text_field来编辑时间,可以这样做: <% f.text_field :due_at_string %> 修改Task类: class Task < ActiveRecord::Base def due_at_stri ...
hideto 评论 (0) 有 1139 人浏览 2011-05-26

Rails宝典之第三十一式: format time

我们经常要用到时间的格式化,我们可以使用ri来看看reference doc. ri Time.strftime 结果显示如下: ------------------------------------------------------- Time#strftime time.strftime( string ) => string -------------------------- ...
hideto 评论 (0) 有 1911 人浏览 2011-05-26

Rails宝典之第三十式: pretty title

这次来看看怎样为每个页面创建良好的title 为了让每个页面显示不同的title,我们需要在global layout -- application中留出位置: <html> <head> <title>Shoppery - <%= yield(:title) || "The Place to Buy Stuff" %>< ...
hideto 评论 (0) 有 1114 人浏览 2011-05-26

Rails宝典之第二十九式: group_by

这次来看active_support/core_ext/enumerable.rb里的group_by: # latest_transcripts.group_by(&:day).each do |day, transcripts| # p "#{day} -> #{transcripts.map(&:class) * ', '}" # end # &qu ...
hideto 评论 (0) 有 1304 人浏览 2011-05-26

Rails宝典之第二十八式: in_groups_of

这次讲的是active_support/core_ext/array/grouping.rb里的in_groups_of方法 # %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g} # ["1", "2", "3"] # ["4", "5", "6&qu ...
hideto 评论 (0) 有 1298 人浏览 2011-05-26

Rails宝典之第二十七式: CSS(Cross Site Scripting)

这次你将看到escape用户输入的任何HTML是多么重要 假设博客上有一个comment表单,我们输入如下内容: Testing <script>alert('test')</script> 提交我们的comment,如果浏览器弹出alert框,说明该博客没有对用户输入的comment进行escape Hacker可以利用这个弱点来做CSS攻击: Got your ...
hideto 评论 (0) 有 1067 人浏览 2011-05-26

Rails宝典之第二十六式: 防止Hacker入侵

假设我们的users表如下: create_table "users", :force => true do |t| t.column "name", :string t.column "admin", :boolean, :default => false, :null => false end 看看我们都创建用户的 ...
hideto 评论 (0) 有 1521 人浏览 2011-05-26

Rails宝典之第二十五式: Sql injection

Sql injection是老问题,对如下查询: def index @tasks = Task.find(:all, :conditions => "name LIKE '%#{params[:query]}%'") end 当用户输入的query条件加上单引号时很容易通过sql injection来攻击我们的Rails程序 而我们使用如下查询方式就可以避免sql注入 ...
hideto 评论 (0) 有 1398 人浏览 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