`
tes
  • 浏览: 7702 次
  • 性别: Icon_minigender_1
  • 来自: 济南
最近访客 更多访客>>
社区版块
存档分类
最新评论
文章列表
Make Dumb Data Smart with composed_of() 通过composed_of() 使呆板的数据变聪明 基本语法如下 class SomeModel < ActiveRecord::Base composed_of :some_attribute, #要添加功能的SomeModel的属性名, #这个属性可以随便起个名不一定是SomeModel 表中的属 ...
Dynamically Configure Your Database 动态的设置你的数据库 有时候不同的操作系统连接数据库的套接字段设置是不同的 如果不同的服务器操作系统不同就需要更改database.yml比较麻烦 但是在database.yml做如下修改就可以避免这个麻烦 development: adapter: mysql database: DynamicDatabaseConfiguration_development username: root password: socket: <%= ["/tmp/mysqld.sock" , &q ...
Add Behavior to Active Record Associations 先贴上数据迁移代码 class AddStudentsTables < ActiveRecord::Migration def self.up create_table :students do |t| t.column :name, :string t.column :graduating_year, :integer end create_table :grades do |t| t.column :student_id, :integer t.column :score, :in ...
Polymorphic Associations—has_many :whatevers Problem 《Rails cookbook》中有一节和这一章类似 通过表中特定的属性区别不同模型的数据实现多态 数据库代码 class AddPeopleCompanyAndAddressTables < ActiveRecord::Migration def self.up create_table :people do |t| t.column :name, :string end create_table :companies do |t| t.column :name, : ...
Many-to-Many Relationships with Extra Data 带有数据的多对多关系 一般多对多关系都带有 一个存储关系的表 这表一般用处比较单一 但是有时也需要在这个表中添加除关系以外的数据 下面有个订杂志的例子 一般情况下 def self.up create_table :magazines do |t| t.column :title, :string end create_table :readers do |t| t.column :name, :string end create_table :magazines_readers, :id = ...
Recipe 17 DRY Up Your Database Configuration 一般设置数据库database.yml: development: adapter: mysql database: DRYUpYourDatabaseConfig_development username: root password: socket: /tmp/mysql.sock test: adapter: mysql database: DRYUpYourDatabaseConfig_test username: root password: socket: /t ...
前几日再看《Rails Cookbook》时有一章叫‘Processing Dynamically Created Input Fields’处理动态创建的输入项(大概是这么翻译吧)觉得挺好可以在以后当作用户权限或角色设置来用。于是实际练了一下但发现一个错误 先把源码发一下,再把错误用有注释标出来 db/schema.rb: ActiveRecord::Schema.define(:version => 0) do create_table "roles", :force => true do |t| t.column "n ...
rails自带In-Place文本编辑,但是我一直想弄一个In-Place的下拉列表前几天在看《Rails Recipes》的时候看见有这么一篇文章,但是试过之后发现在ie下不能正常显示 注释上说是innerhtml的问题。周末在网上搜索了几个解决办法。把自己的实现过程列下来。 js代码放在public文件夹下命名为in_place_select_editor.js Ajax.InPlaceSelectEditor = Class.create(); Object.extend(Object.extend(Ajax.InPlaceSelectEditor.prototype, Ajax.I ...
Global site tag (gtag.js) - Google Analytics