apidock.com Archives - 02 April 2015, Thursday

  • select (ActiveRecord::QueryMethods)

    apidock.com 09 Mar '15, 10pm

    First: takes a block so it can be used just like Array#select. Model . all . select { | m | m . field == value } This will build an array of objects from the database for the scope, converting them into an array and iterating through them using Array#select. Second: Modifies the SELEC...

  • presence (Object)

    apidock.com 09 Mar '15, 3pm

    Returns the receiver if it’s present otherwise returns nil . object.presence is equivalent to object . present? ? object : nil For example, something like state = params [ :state ] if params [ :state ]. present? country = params [ :country ] if params [ :country ]. present? region = s...

  • klass (ActiveRecord::Reflection::AssociationReflection)

    apidock.com 22 Jan '15, 1pm

    Returns the target association’s class. class Author < ActiveRecord :: Base has_many :books end Author . reflect_on_association ( :books ). klass # => Book Note: Do not call klass .new or klass .create to instantiate a new association object. Use build_association or create_associatio...

  • composed_of (ActiveRecord::Aggregations::ClassMethods)

    apidock.com 21 Jan '15, 9am

    :class_name - Specifies the class name of the association. Use it only if that name can’t be inferred from the part id. So composed_of :address will by default be linked to the Address class, but if the real class name is CompanyAddress, you’ll have to specify it with this option. :ma...

  • forty_two (ActiveSupport::CoreExtensions::Array::Access)

    apidock.com 08 Jan '15, 1pm

    This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here. These similar methods exist in v4.1.8: Array#forty_two ActiveRecord::Associations::CollectionAssociation#forty_two ActiveRecord::Associations::CollectionProxy#forty_two A...

  • fetch (Hash)

    apidock.com 08 Jan '15, 2am

    can’t be found, there are several options: With no other arguments, it will raise an KeyError exception; if default is given, then that will be returned; if the optional code block is specified, then that will be run and its result returned.

  • changed_for_autosave? (ActiveRecord::AutosaveAssociation)

    apidock.com 25 Dec '14, 2am

    Returns whether or not this record has been changed in any way (including whether any of its nested autosave associations are likewise changed) Show source # File activerecord/lib/active_record/autosave_association.rb, line 253 def changed_for_autosave? new_record? || changed? || mark...

  • serialize (ActiveRecord::Base)

    apidock.com 25 Oct '14, 10pm

    If you have an attribute that needs to be saved to the database as an object, and retrieved as the same object, then specify the name of that attribute using this method and it will be handled automatically. The serialization is done through YAML . If class_name is specified, the seri...

  • memoize (ActiveSupport::Memoizable)

    apidock.com 27 Sep '14, 6pm

    # include InstanceMethods # if method_defined?(:#{original_method}) # if method_defined?(:_unmemoized_mime_type) raise "Already memoized #{symbol}" # raise "Already memoized mime_type" end # end alias #{original_method} #{symbol} # alias _unmemoized_mime_type mime_type # if instance_m...

  • crypt (String)

    apidock.com 02 Aug '14, 4pm

    From the man page: If salt is a character string starting with the characters “$id$” followed by a string terminated by “$”: $id$salt$encrypted then instead of using the DES machine, id identifies the encryption method used and this then determines how the rest of the password string ...

  • has_many (ActiveRecord::Associations::ClassMethods)

    apidock.com 27 Jul '14, 7am

    Specifies an association through which to perform the query. This can be any other type of association, including other :through associations. Options for :class_name, :primary_key and :foreign_key are ignored, as the association uses the source reflection. If the association on the j...

  • const_set (Module)

    apidock.com 03 Jul '14, 9pm

    Sets the named constant to the given object, returning that object. Creates a new constant if no constant with the given

  • (ActiveResource::Base)

    apidock.com 27 Jun '14, 4pm

    for equality. Resource are equal if and only if other is the same object or is an instance of the same class, is not

  • url_for (ActionView::Helpers::UrlHelper)

    apidock.com 09 Jun '14, 7am

    Specify :host option in emails Emails need a fully qualified URL (with domain). Use the :host parameter. But note also that you need to specify a value that is not dependent upon the request context. http://api.rubyonrails.org/classes/ActionMailer/Base.html recommends setting a defaul...

  • in_groups_of (Array)

    apidock.com 30 May '14, 2pm

    Splits or iterates over the array in groups of size number, padding any remaining slots with

  • layout (AbstractController::Layouts::ClassMethods)

    apidock.com 26 May '14, 8am

    Specify the layout to use for this class. If the specified layout is a: String the String is the template name Symbol call the method specified by the symbol, which will return the template name false There is no layout true raise an ArgumentError nil Force default layout behavior wit...

  • define_method (Module)

    apidock.com 24 May '14, 10pm

    Defines an instance method in the receiver. The method parameter can be a Proc, a Method or an UnboundMethod object. If a block is specified, it is used as the method body. This block is evaluated using instance_eval, a point that is tricky to demonstrate because define_method is priv...

  • validates_with (ActiveModel::Validations::ClassMethods)

    apidock.com 20 May '14, 4am

    :on - Specifies when this validation is active (:create or :update . :if - Specifies a method, proc or string to call to determine if the validation should occur (e.g. if: :allow_validation, or if: Proc.new { |user| user.signup_step > 2 } ). The method, proc or string should return or...

  • syswrite (IO)

    apidock.com 16 May '14, 7am

    written. Do not mix with other methods that write to ios or you may get unpredictable results. Raises

  • inheritance_column (ActiveRecord::ModelSchema::ClassMethods)

    apidock.com 28 Apr '14, 9am

    Defines the name of the table column which will store the class name on single-table inheritance situations. The default inheritance column name is type, which means it’s a reserved word inside Active Record . To be able to use single-table inheritance with another column name, or to ...

  • alias_attribute (Module)

    apidock.com 19 Apr '14, 4pm

    Deprecated - replacement method The description rightly lists this as deprecated, but using it will still work atm, as it seems to have moved to ActiveSupport::CoreExtensions::Module instead. So your code should still work.

  • destroyed? (ActiveRecord::Persistence)

    apidock.com 16 Apr '14, 4am

    Returns true if this object has been destroyed, otherwise returns false. Show source # File activerecord/lib/active_record/persistence.rb, line 77 def destroyed? sync_with_transaction_state @destroyed end

  • to_query (ActiveSupport::CoreExtensions::Hash)

    apidock.com 11 Apr '14, 9am

    This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here. These similar methods exist in v4.0.2: Object#to_query Array#to_query Hash#to_query

  • __callee__ (Kernel)

    apidock.com 08 Apr '14, 11am

    __callee__ and __method__ both return symbol when originally defined, not current There has been some indication that __callee__ is intended to return the symbol with which the method was actually invoked, whereas __method__ returns name with which the method was originally defined, b...

  • create (ActiveRecord::Base)

    apidock.com 04 Apr '14, 8pm

    This method is deprecated or moved on the latest stable version. The last existing version (v3.1.0) is shown here. These similar methods exist in v4.0.2: ActiveRecord::Relation#create ActiveRecord::ConnectionAdapters::MysqlAdapter#create ActiveSupport::TimeZone#create ActiveRecord::As...

  • size (Fixnum)

    apidock.com 24 Mar '14, 8pm

    in the machine representation of a

  • attr_accessor (Module)

    apidock.com 18 Mar '14, 12pm

    Defines a named attribute for this module, where the name is symbol. id2name, creating an instance variable (@name ) and a corresponding access method to read it. Also creates a method called name= to set the attribute.

  • strftime (DateTime)

    apidock.com 08 Mar '14, 12pm

    m blank-padded ( 1..12) %-m no-padded (1..12) %B - The full month name (``January'') %^B uppercased (``JANUARY'') %b - The abbreviated month name (``Jan'') %^b uppercased (``JAN'') %h - Equivalent to %b %d - Day of the month, zero-padded (01..31) %-d no-padded (1..31) %e - Day of the ...

  • ERB

    apidock.com 06 Mar '14, 1pm

    ) returns a string in the same character encoding as the input string. When the input string has a magic comment, however, it returns a string in the encoding specified by the magic comment.

  • find_in_batches (ActiveRecord::Batches)

    apidock.com 03 Mar '14, 10am

    You can control the starting point for the batch processing by supplying the :start option. This is especially useful if you want multiple workers dealing with the same processing queue. You can make worker 1 handle all the records between id 0 and 10,000 and worker 2 handle from 10,0...