Get the Request Media Kind in Rails
Inside a rails controller, this is how you can receive the mime type of the incoming request:
request.media_type # => 'application/x-www-form-urlencoded'
cherry valley forever
todays bird
we're not kids anymore.

祝日 / Permanent Vacation

Stranger Things

⁂

shark vs the universe
🪼
$LAYYYTER
styofa doing anything

❣ Chile in a Photography ❣
Keni
trying on a metaphor
Show & Tell
2025 on Tumblr: Trends That Defined the Year

pixel skylines
Jules of Nature

JVL

blake kathryn
seen from United States
seen from United Kingdom

seen from Australia

seen from Australia
seen from United States

seen from Malaysia

seen from Netherlands

seen from Lithuania

seen from Canada

seen from Austria

seen from United States
seen from France
seen from Netherlands

seen from Malaysia
seen from Romania

seen from United States
seen from United Kingdom

seen from Malaysia

seen from United States
seen from United States
@ruby-101
Get the Request Media Kind in Rails
Inside a rails controller, this is how you can receive the mime type of the incoming request:
request.media_type # => 'application/x-www-form-urlencoded'

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
The three MySQL Gems of Ruby
In the beginning there was nothing.
So God decided to create three different MySQL gems in order to prove all ruby developers.
1) Gem "mysql"
This is the "classical" MySQL gem. It does basically everything and it does it nicely.
Unless you hit the UTF-8 barrier.
2) Gem "mysql2"
This is the gem, which is used by Rails by default. It will do escaping, it will do UTF-8, it will do much for you.
But it is unable to do prepared statements.
3) Gem "ruby-mysql"
This is a very unknown gem, but it can do basically everything: escaping, UTF-8, prepared statements, reconnects - you name it.
If you really need all those features, I'd suggest you to give it a try. Otherwise mysql2 is the way to go.
The only problem is that its documentation is Korean. But you'll find out, that the syntax of the mysql gem simply applies.
And also Google Translator helps.
Substrings in Ruby
Gaining substrings in Ruby is as easy as extracting a range of elements out of an array.
"My supercool text"[9..12] # => "cool"
This will pick out all characters between the ninth and twelfth.
Simultaneously, a negative end point will be handled as a negative offset.
"My supercool text"[9..-1] # => "cool text"
Conditional Thinking in Ruby
In Ruby, there are two ways of doing if-conditions.
a) the classical if-statement b) the cool rubyish unless-statement
Both statements are the opposite of each other. But you should use both and mix 'em up, but in the right way.
Rule #1:
Don't use ever - ever - negative if-conditional statements in ruby. Because that's what unless is for.
"Yes" to this:
unless some_variable.is_a? Integer # Unless some variable is a integer. # Just like you'd read it. ;-) end
"Nope" to this:
if !some_variable.is_a? Integer # Looks ugly, doesn't it? end
Rule #2:
Don't use else statements in unless-expressions.
Why? Because unless something is not something else, something else exactly ist something. Mindfuck.
Rule #3:
Use short-term conditional expressions as much as you can.
First of all, it cleans up your code.
Second: In Ruby, they are like poetry. Take a look:
return false unless my_parameter.is_a? Integer return false if my_parameter > 5
Even Shakespeare couldn't do much better.
Get the current Timestamp in Ruby
Time.now.to_i
The class method now of the class Time creates a time object, representing the current time.
Finally, the Time object is converted into an Integer - you guessed it: that's your current timestamp.

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch • No registration required • HD streaming
Understanding Ruby Methods
In Ruby, basically everything you attach to an object is a method. There are methods, that are easy to identify as a method, like:
['This', 'is', 'crazy', 'ruby', 'syntax'].join(' ')
There are instance variables, whose you can set and get:
cool_object.variable # => 'amazing' cool_object.variable = 'nice'
... but you are actually calling setter and getter methods:
class cool_object def variable return @variable # you could drop 'return' here... end def variable=(value) @variable = value end end
There are known symbols:
packed_array[0] # => 'cool item'
... and lesser-known symbols:
packed_array << 'new item'
... that are synonyms for
packed_array.at(0) # => 'cool item' packed_array.push('new item')
Yes, even == is a method (for an array).
Extracting Array Elements in Ruby
In Ruby, you can get multiple values from an array by accessing it via a given range.
Let's take this array:
my_rocking_array = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
... and return a single value:
my_rocking_array[1] # => 'b'
... or return a range of values:
my_rocking_array[1..3] # => ['b', 'c', 'd']
... of course, also this works:
my_rocking_array[1, 3] # => ['b', 'c', 'd']
Handling arrays in ruby is very easy.
Random Int between 0 and 100 in Ruby
(0..100).to_a.sample
(0..100) creates a range of ints, which is converted into an array. Finally, sample picks out a random element of the given array.
Et voilà, you now have a random int between 0 and 100.