instance method to_fs

Ruby on Rails 8.1.2

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

to_fs(format = :default)

Extends Array#to_s to convert a collection of elements into a comma separated id list if :db argument is given as the format.

This method is aliased to to_formatted_s.

Blog.all.to_fs(:db)  # => "1,2,3"
Blog.none.to_fs(:db) # => "null"
[1,2].to_fs          # => "[1, 2]"

Parameters

format opt = :default
Source
# File activesupport/lib/active_support/core_ext/array/conversions.rb, line 94
  def to_fs(format = :default)
    case format
    when :db
      if empty?
        "null"
      else
        collect(&:id).join(",")
      end
    else
      to_s
    end
  end

Defined in activesupport/lib/active_support/core_ext/array/conversions.rb line 94 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Array

Type at least 2 characters to search.

↑↓ navigate · open · esc close