最全的 Ruby/ Rails 保留字 ( ruby/rails reserved words complete )

访问量: 7675

原文见: http://latheesh.com/2010/02/02/rails-reserved-words/

ruby

Rails doesn’t like it if you name your models and columns some of the words that it uses in the framework. This is a collection of those words so that a lot of the confusion can be avoided.

Reserved Words:

  • ADDITIONAL_LOAD_PATHS
  • ARGF
  • ARGV
  • ActionController
  • ActionView
  • ActiveRecord
  • ArgumentError
  • Array
  • BasicSocket
  • Benchmark
  • Bignum
  • Binding
  • CGI
  • CGIMethods
  • CROSS_COMPILING
  • Class
  • ClassInheritableAttributes
  • Comparable
  • ConditionVariable
  • Config
  • Continuation
  • DRb
  • DRbIdConv
  • DRbObject
  • DRbUndumped
  • Data
  • Date
  • DateTime
  • Delegater
  • Delegator
  • Digest
  • Dir
  • ENV
  • EOFError
  • ERB
  • Enumerable
  • Errno
  • Exception
  • FALSE
  • FalseClass
  • Fcntl
  • File
  • FileList
  • FileTask
  • FileTest
  • FileUtils
  • Fixnum
  • Float
  • FloatDomainError
  • GC
  • Gem
  • GetoptLong
  • Hash
  • IO
  • IOError
  • IPSocket
  • IPsocket
  • IndexError
  • Inflector
  • Integer
  • Interrupt
  • Kernel
  • LN_SUPPORTED
  • LoadError
  • LocalJumpError
  • Logger
  • Marshal
  • MatchData
  • MatchingData
  • Math
  • Method
  • Module
  • Mutex
  • Mysql
  • MysqlError
  • MysqlField
  • MysqlRes
  • NIL
  • NameError
  • NilClass
  • NoMemoryError
  • NoMethodError
  • NoWrite
  • NotImplementedError
  • Numeric
  • OPT_TABLE
  • Object
  • ObjectSpace
  • Observable
  • Observer
  • PGError
  • PGconn
  • PGlarge
  • PGresult
  • PLATFORM
  • PStore
  • ParseDate
  • Precision
  • Proc
  • Process
  • Queue
  • RAKEVERSION
  • RELEASE_DATE
  • RUBY
  • RUBY_PLATFORM
  • RUBY_RELEASE_DATE
  • RUBY_VERSION
  • Rack
  • Rake
  • RakeApp
  • RakeFileUtils
  • Range
  • RangeError
  • Rational
  • Regexp
  • RegexpError
  • Request
  • RuntimeError
  • STDERR
  • STDIN
  • STDOUT
  • ScanError
  • ScriptError
  • SecurityError
  • Signal
  • SignalException
  • SimpleDelegater
  • SimpleDelegator
  • Singleton
  • SizedQueue
  • Socket
  • SocketError
  • StandardError
  • String
  • StringScanner
  • Struct
  • Symbol
  • SyntaxError
  • SystemCallError
  • SystemExit
  • SystemStackError
  • TCPServer
  • TCPSocket
  • TCPserver
  • TCPsocket
  • TOPLEVEL_BINDING
  • TRUE
  • Task
  • Text
  • Thread
  • ThreadError
  • ThreadGroup
  • Time
  • Transaction
  • TrueClass
  • TypeError
  • UDPSocket
  • UDPsocket
  • UNIXServer
  • UNIXSocket
  • UNIXserver
  • UNIXsocket
  • UnboundMethod
  • Url
  • VERSION
  • Verbose
  • YAML
  • ZeroDivisionError

Other Problematic Names:

  • accept
  • callback – breaks validation if used as a model method.
  • categorie
  • action
  • attributes – if you have a has_many called attributes, you can’t access to your object attributes anymore; only the associated objects
  • application2
  • @base_path – setting this variable name in a controller method seems to break the ablity to render a partial in the view. The view will render with no content and no errors will be generated .
  • connection – there seems to be a connection class already
  • database – (in mysql)
  • dispatcher
  • display1
  • drive – fixtures will not autogenerate IDs in Rails 2.0.2
  • errors
  • format
  • host – I had a text_field :host, :name that I saw problems with. (JR)
  • key
  • layout – If you have a model called Layout and in a controller have “scaffold :layout” it generates an exception. However, if you script/generate the scaffold for layout it works.
  • load – When making an Ajax call to an action named load, the action’s code will be skipped (or otherwise rendered useless). This is made apparent by: a) @variables are not available in the view, b) calling render :layout => false still yields the layout.
  • link – breaks migrations when used as a column name in combination with validation: ticket
  • new, override to news if you want a news table
  • notify – not a valid column name
  • open – not a valid column name
  • public
  • quote ‘quote’ cannot be used as a column name
  • render – cannot be used as an action name
  • request
  • records – a table named records seemed to cause duplicate entries to be found by find
  • responses – scaffold borks with “undefined method ‘body=’ “
  • save – ActiveRecord uses this to save the object.
  • scope – do not use as an association name because ActiveRecord::Base.scope is called instead
  • send
  • session (session_controller or SessionController will not work)
  • system – a table column named system causes problems when trying to generate scaffold
  • template – a table named templates causes an error when you try to invoke the create method of the default controller
  • test (however those work with ruby test/unit/axistest.rb_ and rake testunits_)
  • timeout – an ActiveRecord attribute named timeout will clash with the global function “timeout” defined in Ruby’s timeout.rb
  • to_s — naming a model instance method to_s resulted in ‘File not found’ for any view an object of this class (should have) appeared in (no matter which method called) and WebRick had to be restarted. I couldn’t drag the very cause into light, but in the traces ‘to_s’ gave me a hint. After renaming everything worked well again.
  • type — or any of the other MagicFieldNames
  • URI
  • visits — a table column named visits causes problems when trying to query some_obj.visits.
  • Observer — for a model name works in development environment but not in production.
    singular names finishing in “s”: Axis → Axes, Access → Accesses, will break the pluralization in rake: Axi, Acces

Magic Field Names:

  • created_at
  • created_on
  • updated_at
  • updated_on
  • lock_version
  • type
  • id
  • #{table_name}_count
  • position
  • parent_id
  • lft
  • rgt
  • quote_value (is used for quoting)
  • template

Reserved Words for Various SQL Databases:

A, ABORT, ABS, ABSOLUTE, ACCESS, ACTION, ADA, ADD, ADMIN, AFTER, AGGREGATE, ALIAS, ALL, ALLOCATE, ALSO, ALTER, ALWAYS, ANALYSE, ANALYZE, AND, ANY, ARE, ARRAY, AS, ASC, ASENSITIVE, ASSERTION, ASSIGNMENT, ASYMMETRIC, AT, ATOMIC, ATTRIBUTE, ATTRIBUTES, AUTHORIZATION, AVG, BACKUP, BACKWARD, BEFORE, BEGIN, BERNOULLI, BETWEEN, BIGINT, BINARY, BIT, BITVAR, BIT_LENGTH, BLOB, BOOLEAN, BOTH, BREADTH, BREAK, BROWSE, BULK, BY, C, CACHE, CALL, CALLED, CARDINALITY, CASCADE, CASCADED, CASE, CAST, CATALOG, CATALOG_NAME, CEIL, CEILING, CHAIN, CHANGE, CHAR, CHARACTER, CHARACTERISTICS, CHARACTERS, CHARACTER_LENGTH, CHARACTER_SET_CATALOG, CHARACTER_SET_NAME, CHARACTER_SET_SCHEMA, CHAR_LENGTH, CHECK, CHECKED, CHECKPOINT, CLASS, CLASS_ORIGIN, CLOB, CLOSE, CLUSTER, CLUSTERED, COALESCE, COBOL, COLLATE, COLLATION, COLLATION_CATALOG, COLLATION_NAME, COLLATION_SCHEMA, COLLECT, COLUMN, COLUMN_NAME, COMMAND_FUNCTION, COMMAND_FUNCTION_CODE, COMMENT, COMMIT, COMMITTED, COMPLETION, COMPUTE, CONCURRENTLY, CONDITION, CONDITION_NUMBER, CONNECT, CONNECTION, CONNECTION_NAME, CONSTRAINT, CONSTRAINTS, CONSTRAINT_CATALOG, CONSTRAINT_NAME, CONSTRAINT_SCHEMA, CONSTRUCTOR, CONTAINS, CONTAINSTABLE, CONTINUE, CONVERSION, CONVERT, COPY, CORR, CORRESPONDING, COUNT, COVAR_POP, COVAR_SAMP, CREATE, CREATEDB, CREATEROLE, CREATEUSER, CROSS, CSV, CUBE, CUME_DIST, CURRENT, CURRENT_DATE, CURRENT_DEFAULT_TRANSFORM_GROUP, CURRENT_PATH, CURRENT_ROLE, CURRENT_TIME, CURRENT_TIMESTAMP, CURRENT_TRANSFORM_GROUP_FOR_TYPE, CURRENT_USER, CURSOR, CURSOR_NAME, CYCLE, DATA, DATABASE, DATABASES, DATE, DATETIME_INTERVAL_CODE, DATETIME_INTERVAL_PRECISION, DAY, DAY_HOUR, DAY_MICROSECOND, DAY_MINUTE, DAY_SECOND, DBCC, DEALLOCATE, DEC, DECIMAL, DECLARE, DEFAULT, DEFAULTS, DEFERRABLE, DEFERRED, DEFINED, DEFINER, DEGREE, DELAYED, DELETE, DELIMITER, DELIMITERS, DENSE_RANK, DENY, DEPTH, DEREF, DERIVED, DESC, DESCRIBE, DESCRIPTOR, DESTROY, DESTRUCTOR, DETERMINISTIC, DIAGNOSTICS, DICTIONARY, DISABLE, DISCONNECT, DISK, DISPATCH, DISTINCT, DISTINCTROW, DISTRIBUTED, DIV, DO, DOMAIN, DOUBLE, DROP, DUAL, DUMMY, DUMP, DYNAMIC, DYNAMIC_FUNCTION, DYNAMIC_FUNCTION_CODE, EACH, ELEMENT, ELSE, ELSEIF, ENABLE, ENCLOSED, ENCODING, ENCRYPTED, END, END-EXEC, EQUALS, ERRLVL, ESCAPE, ESCAPED, EVERY, EXCEPT, EXCEPTION, EXCLUDE, EXCLUDING, EXCLUSIVE, EXEC, EXECUTE, EXISTING, EXISTS, EXIT, EXP, EXPLAIN, EXTERNAL, EXTRACT, FALSE, FETCH, FILE, FILLFACTOR, FILTER, FINAL, FIRST, FLOAT, FLOAT4, FLOAT8, FLOOR, FOLLOWING, FOR, FORCE, FOREIGN, FORTRAN, FORWARD, FOUND, FREE, FREETEXT, FREETEXTTABLE, FREEZE, FROM, FULL, FULLTEXT, FUNCTION, FUSION, G, GENERAL, GENERATED, GET, GLOBAL, GO, GOTO, GRANT, GRANTED, GREATEST, GROUP, GROUPING, HANDLER, HAVING, HEADER, HIERARCHY, HIGH_PRIORITY, HOLD, HOLDLOCK, HOST, HOUR, HOUR_MICROSECOND, HOUR_MINUTE, HOUR_SECOND, IDENTITY, IDENTITYCOL, IDENTITY_INSERT, IF, IGNORE, ILIKE, IMMEDIATE, IMMUTABLE, IMPLEMENTATION, IMPLICIT, IN, INCLUDE, INCLUDING, INCREMENT, INDEX, INDEXES, INDICATOR, INFILE, INFIX, INHERIT, INHERITS, INITIALIZE, INITIALLY, INNER, INOUT, INPUT, INSENSITIVE, INSERT, INSTANCE, INSTANTIABLE, INSTEAD, INT, INT1, INT2, INT3, INT4, INT8, INTEGER, INTERSECT, INTERSECTION, INTERVAL, INTO, INVOKER, IS, ISNULL, ISOLATION, ITERATE, JOIN, K, KEY, KEYS, KEY_MEMBER, KEY_TYPE, KILL, LANCOMPILER, LANGUAGE, LARGE, LAST, LATERAL, LEADING, LEAST, LEAVE, LEFT, LENGTH, LESS, LEVEL, LIKE, LIMIT, LINENO, LINES, LISTEN, LN, LOAD, LOCAL, LOCALTIME, LOCALTIMESTAMP, LOCATION, LOCATOR, LOCK, LOGIN, LONG, LONGBLOB, LONGTEXT, LOOP, LOWER, LOW_PRIORITY, M, MAP, MATCH, MATCHED, MAX, MAXVALUE, MEDIUMBLOB, MEDIUMINT, MEDIUMTEXT, MEMBER, MERGE, MESSAGE_LENGTH, MESSAGE_OCTET_LENGTH, MESSAGE_TEXT, METHOD, MIDDLEINT, MIN, MINUTE, MINUTE_MICROSECOND, MINUTE_SECOND, MINVALUE, MOD, MODE, MODIFIES, MODIFY, MODULE, MONTH, MORE, MOVE, MULTISET, MUMPS, NAME, NAMES, NATIONAL, NATURAL, NCHAR, NCLOB, NESTING, NEW, NEXT, NO, NOCHECK, NOCREATEDB, NOCREATEROLE, NOCREATEUSER, NOINHERIT, NOLOGIN, NONCLUSTERED, NONE, NORMALIZE, NORMALIZED, NOSUPERUSER, NOT, NOTHING, NOTIFY, NOTNULL, NOWAIT, NO_WRITE_TO_BINLOG, NULL, NULLABLE, NULLIF, NULLS, NUMBER, NUMERIC, OBJECT, OCTETS, OCTET_LENGTH, OF, OFF, OFFSET, OFFSETS, OIDS, OLD, ON, ONLY, OPEN, OPENDATASOURCE, OPENQUERY, OPENROWSET, OPENXML, OPERATION, OPERATOR, OPTIMIZE, OPTION, OPTIONALLY, OPTIONS, OR, ORDER, ORDERING, ORDINALITY, OTHERS, OUT, OUTER, OUTFILE, OUTPUT, OVER, OVERLAPS, OVERLAY, OVERRIDING, OWNED, OWNER, PAD, PARAMETER, PARAMETERS, PARAMETER_MODE, PARAMETER_NAME, PARAMETER_ORDINAL_POSITION, PARAMETER_SPECIFIC_CATALOG, PARAMETER_SPECIFIC_NAME, PARAMETER_SPECIFIC_SCHEMA, PARTIAL, PARTITION, PASCAL, PASSWORD, PATH, PERCENT, PERCENTILE_CONT, PERCENTILE_DISC, PERCENT_RANK, PLACING, PLAN, PLI, POSITION, POSTFIX, POWER, PRECEDING, PRECISION, PREFIX, PREORDER, PREPARE, PREPARED, PRESERVE, PRIMARY, PRINT, PRIOR, PRIVILEGES, PROC, PROCEDURAL, PROCEDURE, PUBLIC, PURGE, QUOTE, RAID0, RAISERROR, RANGE, RANK, READ, READS, READTEXT, REAL, REASSIGN, RECHECK, RECONFIGURE, RECURSIVE, REF, REFERENCES, REFERENCING, REGEXP, REGR_AVGX, REGR_AVGY, REGR_COUNT, REGR_INTERCEPT, REGR_R2, REGR_SLOPE, REGR_SXX, REGR_SXY, REGR_SYY, REINDEX, RELATIVE, RELEASE, RENAME, REPEAT, REPEATABLE, REPLACE, REPLICATION, REQUIRE, RESET, RESIGNAL, RESTART, RESTORE, RESTRICT, RESULT, RETURN, RETURNED_CARDINALITY, RETURNED_LENGTH, RETURNED_OCTET_LENGTH, RETURNED_SQLSTATE, RETURNING, RETURNS, REVOKE, RIGHT, RLIKE, ROLE, ROLLBACK, ROLLUP, ROUTINE, ROUTINE_CATALOG, ROUTINE_NAME, ROUTINE_SCHEMA, ROW, ROWCOUNT, ROWGUIDCOL, ROWS, ROW_COUNT, ROW_NUMBER, RULE, SAVE, SAVEPOINT, SCALE, SCHEMA, SCHEMAS, SCHEMA_NAME, SCOPE, SCOPE_CATALOG, SCOPE_NAME, SCOPE_SCHEMA, SCROLL, SEARCH, SECOND, SECOND_MICROSECOND, SECTION, SECURITY, SELECT, SELF, SENSITIVE, SEPARATOR, SEQUENCE, SERIALIZABLE, SERVER_NAME, SESSION, SESSION_USER, SET, SETOF, SETS, SETUSER, SHARE, SHOW, SHUTDOWN, SIGNAL, SIMILAR, SIMPLE, SIZE, SMALLINT, SOME, SONAME, SOURCE, SPACE, SPATIAL, SPECIFIC, SPECIFICTYPE, SPECIFIC_NAME, SQL, SQLCA, SQLCODE, SQLERROR, SQLEXCEPTION, SQLSTATE, SQLWARNING, SQL_BIG_RESULT, SQL_CALC_FOUND_ROWS, SQL_SMALL_RESULT, SQRT, SSL, STABLE, START, STARTING, STATE, STATEMENT, STATIC, STATISTICS, STDDEV_POP, STDDEV_SAMP, STDIN, STDOUT, STORAGE, STRAIGHT_JOIN, STRICT, STRUCTURE, STYLE, SUBCLASS_ORIGIN, SUBLIST, SUBMULTISET, SUBSTRING, SUM, SUPERUSER, SYMMETRIC, SYSID, SYSTEM, SYSTEM_USER, TABLE, TABLESAMPLE, TABLESPACE, TABLE_NAME, TEMP, TEMPLATE, TEMPORARY, TERMINATE, TERMINATED, TEXTSIZE, THAN, THEN, TIES, TIME, TIMESTAMP, TIMEZONE_HOUR, TIMEZONE_MINUTE, TINYBLOB, TINYINT, TINYTEXT, TO, TOP, TOP_LEVEL_COUNT, TRAILING, TRAN, TRANSACTION, TRANSACTIONS_COMMITTED, TRANSACTIONS_ROLLED_BACK, TRANSACTION_ACTIVE, TRANSFORM, TRANSFORMS, TRANSLATE, TRANSLATION, TREAT, TRIGGER, TRIGGER_CATALOG, TRIGGER_NAME, TRIGGER_SCHEMA, TRIM, TRUE, TRUNCATE, TRUSTED, TSEQUAL, TYPE, UESCAPE, UNBOUNDED, UNCOMMITTED, UNDER, UNDO, UNENCRYPTED, UNION, UNIQUE, UNKNOWN, UNLISTEN, UNLOCK, UNNAMED, UNNEST, UNSIGNED, UNTIL, UPDATE, UPDATETEXT, UPPER, USAGE, USE, USER, USER_DEFINED_TYPE_CATALOG, USER_DEFINED_TYPE_CODE, USER_DEFINED_TYPE_NAME, USER_DEFINED_TYPE_SCHEMA, USING, UTC_DATE, UTC_TIME, UTC_TIMESTAMP, VACUUM, VALID, VALIDATOR, VALUE, VALUES, VARBINARY, VARCHAR, VARCHARACTER, VARIABLE, VARYING, VAR_POP, VAR_SAMP, VERBOSE, VIEW, VOLATILE, WAITFOR, WHEN, WHENEVER, WHERE, WHILE, WIDTH_BUCKET, WINDOW, WITH, WITHIN, WITHOUT, WORK, WRITE, WRITETEXT, X509, XOR, YEAR, YEAR_MONTH, ZEROFILL, ZONE

Reference:

http://oldwiki.rubyonrails.org/rails/pages/ReservedWords

订阅/RSS Feed

Subscribe

分类/category