Access just the label text

chiperific Apr 5, 2021

One of the handiest features of f.submit is the auto-generated label text.

Some styling frameworks don't lend themselves to using f.submit without lots of tweaking.

If you're not using f.submit but still want to access the label text, note that there is a private method:

f.send(:submit_...

Text improvement

xlembouras Mar 10, 2021

The statement about not loading a bunch of records is correct because pluck returns an Array of values, not a ActiveRecord::Relation or an Array of Records.

The exact wording though may be:

"...without retrieving from the database unused columns or loading a bunch of records just to grab the att...

Make your custom enumerable "flattenable"

stevo May 5, 2020

Just alias +to_a+ to +to_ary+

class A
include Enumerable

def each
  yield "a"
  yield "b"
end
end


[A.new, A.new].flatten => [#<A:0x00007fbddf1b5d88>, #<A:0x00007fbddf1b5d60>]


class A
def to_ary
  to_a
end
end

[A.new, A.new].flatten =>...

Works even on nested structures

mltsy Apr 2, 2020

@EdvardM added a note years ago saying this does not symbolize the keys of deeply nested hashes, which may have been the case for whatever version of ruby was available at the time, but in 4+, it definitely does work as described:

hash = {"a" => :a, "b" => {z: [[{"c" => 3}, {"c" => 4}], []]}}...

to_sentence_exclusive

joshuapinter May 28, 2019

By default, +to_sentence+ combines elements inclusively by using ", and ".

If you want to be exclusive and combine the elements using ", or ", you can either pass in lengthy options to +to_sentence+ or use this handy extension I made to add +to_sentence_exclusive+ to the +Array+...

Upload Files Directly To S3 Using Paperclip And Dropzone.js

rubyonrailsdevelopment Jun 4, 2018

Upload Files Directly To S3 Using Paperclip And Dropzone.js

by | Dec 22, 2017 | Technical Articles | 0 comments

It’s usually the small time-consuming tasks that frustrate us the most. Such as uploading a file to S3; the requirement is pretty simple but the method chosen to upload the file will dec...

Urlify Functions & Its Implementation

rubyonrailsdevelopment Jun 4, 2018

URLify is a simple gem that refines the conversion of UTF-8 strings to ASCII-safe URI strings and enables it to be used as readable URL-segments. After the gem is installed, you can call the URLify function for any UTF-8 string and it will be automatically converted into an ASCII-safe URI string. UR...

Effectively identical to Hash#as_json

SirRamonGabriel Dec 20, 2017

As of 5.2.0.beta, there is no ActiveRecord::Relation specific implementation. This will result in Object#as_json , which will convert the relation to a hash and call Hash#as_json .

class Object
def as_json(options = nil) #:nodoc:
  if respond_to?(:to_hash)
    to_hash.as_json(option...