代码改变世界

Rails 3 validates验证器

2013-07-13 02:21 by 张小萌, 185 阅读, 0 推荐, 收藏, 编辑
摘要:之前:def validate if baggage >flight.baggage_allowance errors.add_to_base("You have too much baggage")endif flight.seats.size >= flight.capacity errors.add_to_base("The flight is fully booked")endendendRails 3:validate :baggage_does_not_exceed_baggage_capacity, :seats_availab 阅读全文

非支架生成的情况下,验证错误信息输出方法,<%= f.error_messages %>错误

2013-07-11 01:39 by 张小萌, 188 阅读, 0 推荐, 收藏, 编辑
摘要:rails3下,替换为 prohibited this post from being saved: 阅读全文

rails 检查器

2013-07-11 00:59 by 张小萌, 336 阅读, 0 推荐, 收藏, 编辑
摘要:1、message 用于报错是的提示内容class Account "你的 Email 重複了"end2、validates_presence_of用于检查是否为空validates_presence_of :name3、validates_length_of用于检查字符串长度validates_length_of :name, :minimum => 2 # 最少 24、validates_numericality_of用于检查是否为数字validates_numericality_of :games_played, :only_integer => true 阅读全文

提高rails new时bundle install的速度方法

2013-07-10 00:42 by 张小萌, 342 阅读, 0 推荐, 收藏, 编辑
摘要:方法1、rails new my_app --skip-bundle cd my_app bundle install --local方法2、使用新版的bundle gem install bundler --pre 阅读全文

rails路由常用请求类型

2013-07-08 23:09 by 张小萌, 218 阅读, 0 推荐, 收藏, 编辑
摘要:HTTPVerbPathactionused forGET/photosindexdisplay a list of all photosGET/photos/newnewreturn anHTMLform for creating a new photoPOST/photoscreatecreate a new photoGET/photos/:idshowdisplay a specific photoGET/photos/:id/editeditreturn anHTMLform for editing a photoPATCH/PUT/photos/:idupdateupdate a 阅读全文

rails 表单路由设置以及rails4.0 create引起的ActiveModel::ForbiddenAttributesError错误

2013-07-07 23:17 by 张小萌, 927 阅读, 0 推荐, 收藏, 编辑
摘要:表单路由设置:post '/ads/create‘=>’ads#create'表单页面路由设置:get'/ads/new'=>'ads#new'map.connect ':controller/:action/:id'和 map.connect ':controller/:action/:id.:format' 在rails3里为match ':controller(/:action(/:id(/:format)))',via:[:get,:post]map.connect'pr 阅读全文

Rails 数据库删除table

2013-07-07 03:50 by 张小萌, 349 阅读, 0 推荐, 收藏, 编辑
摘要:1、先rails generate migration DropProductsTable来生成操作数据库的rb代码文件2、在db/migrate文件下找到找到生成的文件,在def change下加入drop_table :ads3、然后执行rake db:migrate,默认会执行最新的migrate文件,删除ads table。 阅读全文

Address already in use - bind(2)

2013-07-03 02:17 by 张小萌, 234 阅读, 0 推荐, 收藏, 编辑
摘要:Address already in use - bind(2)这个是因为之前的pid没有退出,在进程里面找到ruby这个进程杀掉 阅读全文

Rails一些命令的变化

2013-07-03 01:54 by 张小萌, 141 阅读, 0 推荐, 收藏, 编辑
摘要:rails generateorrails g替代了script/generaterails server orrails s 替代了script/serverrails 2 ->3路由变化:map.connect '/ads/:id', :controller=>'ads', action=>'show'变更为match '/ads/:id' => 'ads#show',:via => :get 或者get '/ads/:id' => 'ads#show 阅读全文

rails使用出错

2013-07-02 01:39 by 张小萌, 227 阅读, 0 推荐, 收藏, 编辑
摘要:rails -v 或者rails创建时候报错误:(来自网上,自己的错误忘记报错了,基本类似这样)/Users/hb/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in`to_specs': Could not find railties (>= 0) amongst [bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError 阅读全文