rails知识
liuk10
Ruby On Rails开发工程师
展开
-
Ruby On Rails--rake 任务中定义方法的陷阱
问题描述在rails项目中,有时候需要导出数据、处理历史数据等,这时用rake是很方便的。在rake中,有时候由于逻辑比较复杂,所以我们就会分离逻辑或者需要重用代码,这时候可能会定义方法。但是,在rake中定义方法有一个问题:在不同rake文件和不同命名空间下定义的方法,如果存在了同名方法,那么后来定义的方法会覆盖掉之前定义的方法,这时候可能会导致bug。下面我们用一个例子来具体说明下: 比如有个原创 2016-04-06 17:35:48 · 1303 阅读 · 0 评论 -
Ruby On Rails--Active Record Callbacks(回调)
Callbacks allow you to trigger logic before or after an alteration of an object’s state’. Active Record Callbacks知识总览官方文档对象的生命周期什么是Callbacks如何使用Callbacks有哪些可用的Callbacks 创建对象时被调用 before_validation afte原创 2016-04-07 16:30:20 · 938 阅读 · 0 评论 -
Ruby On Rails--Active Record Associations(关联关系)
Why do we need associations between models? Because they make common operations simpler and easier in your code. Active Record Associations知识总览官方文档为什么使用Associations ?Associations的类型 belongs_to has_one原创 2016-04-07 17:04:19 · 543 阅读 · 0 评论 -
Ruby On Rails--Active Record Migrations(数据库迁移)
Migrations are a convenient way to alter your database schema over time in a consistent and easy way. Active Record Migrations知识总览官方文档 如何用Rails的命令创建migration Rails和数据库对应的基本的类型有哪些 创建表 添加索引(唯一性索引,联合索引等)原创 2016-04-07 17:07:06 · 751 阅读 · 0 评论 -
Ruby On Rails--Active Record Validations(校验)
Validations are used to ensure that only valid data is saved into your database. Active Record Validations知识总览官方文档 什么是validate validate发生在什么地方 绕过校验 validate: false 校验是如何触发的? 校验的几种形式 validates_XXX_of,原创 2016-04-07 17:08:47 · 717 阅读 · 0 评论 -
Ruby On Rails--Active Record Query Interface(数据库查询)
Active Record will perform queries on the database for you and is compatible with most database systems (MySQL, PostgreSQL and SQLite to name a few). Active Record Query Interface知识总览官方文档从数据库检索对象 查询方法b原创 2016-04-07 17:10:19 · 574 阅读 · 0 评论 -
Ruby On Rails--Action Controller(控制器)
Action Controller知识总览Action Controller Overview Action Controller is the C in MVC. After routing has determined which controller to use for a request, your controller is responsible for making sense原创 2016-04-07 17:12:18 · 3572 阅读 · 0 评论 -
Ruby On Rails--Layouts and Rendering in Rails(布局和页面渲染)
Layouts and Rendering in Rails 知识总览官方文档 同一个action中,render和redirect_to不能同时调用,也不能重复调用任意一个。 Rails默认render renderan Action’s View :nothing :file :action :template :plain :html :json :js :xml :content_type原创 2016-04-07 17:14:24 · 630 阅读 · 0 评论 -
Ruby On Rails--Action View Form Helpers(页面表单帮助方法)
Action View Form Helpers 知识总览官方文档基础Form表单的Helper方法 form_tag方法及其选项:method :controller :action :class, :style, :id, … label_tag text_field_tag, text_area_tag submit_tag check_box_tag radio_button_tag pas原创 2016-04-07 17:15:37 · 901 阅读 · 0 评论