Rails rails g model 的问题

shangrenzhidao · 2013年11月08日 · 最后由 shangrenzhidao 回复于 2013年11月08日 · 3262 次阅读

我在 rails g model 后,发现忘记写了一个属性,是不是要把之前的全部删掉,重新执行一次呢?

rails s model, 没有这个命令。忘记漏写当然不需要了重写了,你只要 rails g migration add_your_field_to_model 就可以了

git status 看看有啥改动就知道了,改啥删啥

#1 楼 @hanluner rails g migration event capacity:integer SECURITY WARNING: No secret option provided to Rack::Session::Cookie. This poses a security threat. It is strongly recommended that you provide a secret to prevent exploits that may be possible from crafted cookies. This will not be supported in future versions of Rack, and future versions will even invalidate your existing user cookies.

Called from: /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.7/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

invoke active_record create db/migrate/20131108072054_event.rb 这样是不是可以了?谢谢,那个是 g ,手误

我一向是生成空 model 再手写 migration。

少写了就建立个 migration,rails g migration add__to** ,然后再 change 里面写上 add_column: :tables_name , :column_name , :data_type

#4 楼 @Rei 嗯,这个办法也不错

#2 楼 @501225658 嘿嘿 忘记 git 初始化了

#7 楼 @shangrenzhidao 你没有明白我的意思,以及那个谁的意思。看一下 rails guide 吧 http://guides.rubyonrails.org/migrations.html#creating-a-migration

#8 楼 @hanluner 我看了,作为一个刚刚入门的人或者这么说不恰当,如果项目变化几次需要增加属性的话,次数多了,代码会不会很臃肿?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号