新手问题 rails model 属性 使用 问题

tank_lei · October 30, 2013 · Last by tank_lei replied at October 30, 2013 · 3443 hits

现在是用的 rails4.0, 我们 model 生成的时候,就有指定属性 eg: railg g model post title:string

这里我们在 class Post < ActiveRecord::Base end 里面并没有看到 title 属性

但我们可以直接使用,我想知道这里是在那关联上的? 在迁移文件里面有,但那是跟数据库挂钩的。

这个就是框架给你提供的方法,详细的你可以查阅下 ActiveRecord 的相关资料 :http://ihower.tw/rails3/activerecord.html

你就是不写 rails 里,只加在数据库里,这里也有,因为他是动态的

#1 楼 @Shadow 恩,好的,谢谢!

#2 楼 @ZombieCoder 哦,原来如此,这个作用太神器了!

You need to Sign in before reply, if you don't have an account, please Sign up first.