在Rails / ActiveRecord列名称中使用问号字符 [英] Using question mark character in Rails/ActiveRecord column name

查看:68
本文介绍了在Rails / ActiveRecord列名称中使用问号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与Ruby在布尔方法(例如 person.is_smart?)中使用问号的惯用法保持一致,我想对Rails:

In keeping with Ruby's idiom of using a question mark in boolean methods (e.g. person.is_smart?), I'd like to do the same for an ActiveRecord field in Rails:

rails generate model Person is_smart?:boolean

我实际上没有运行上面的语句。我假设数据库字段中不能包含问号。 Rails会适当处理吗?

I haven't actually run the above statement. I assume that database fields can't have a question mark in them. Will rails deal with this appropriately? Is the best practice to simply leave question marks off of models?

使用Rails 3.2.8

Using Rails 3.2.8

推荐答案

如果存在名为'smart' smart? >。

Rails will automatically generate the method smart? if there is a field named 'smart'.

这篇关于在Rails / ActiveRecord列名称中使用问号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆