if you are using turbolink there are links to sites where you might not want that turbolink is used.
you can prevent that by adding "data-turbolinks" => "false"
<%= link_to "link", "/link","data-turbolinks" => "false" %>
Devs at IST are sharing things
if you are using turbolink there are links to sites where you might not want that turbolink is used.
you can prevent that by adding "data-turbolinks" => "false"
<%= link_to "link", "/link","data-turbolinks" => "false" %>
If you want to show a text with all html formatting html_safe doesn’t work but this line of code
ActionView::Base.full_sanitizer.sanitize(@string)
there is a lot of different pagination gem. while will_paginate is quite good I recommend Kamari because it also can page arrays and not only ActiveRecord::Relation
if you have a string containing blank characters you get rid of them using this function
field.gsub("\s",'')
or if you are on ruby on rails 2.4 you can also use
field.delete("\s")
lets say you have a hash
hh = {1=>'y', 2=>'a'}
if you need to sort a hash by its value this works like this
Hash[hh.sort_by{|k, v| v}]
in case your hash looks like this
hh = {1=>'y',2=>'A'}
you should be aware to change your value to lower case like this
Hash[hh.sort_by{|k, v| v.downcase}]
in case your hash looks like this
hh = {1=>0.0,2=>nil,3=>4.0}
you need to replace nil with a sortable value
hh.sort_by{|k, v| v ? v : 0}
I had a problem caused by the sub! function.
What I did:
myobj = Model.create({"field"=>"text"})
myobj.field.sub! "text", "replacedwith"
myobj.save
puts myobj.field
#returns replacedwith
myobj.reload
puts myobj.field
#returns text
using this line it works
myobj.field = myobj.field.sub "text", "replacedwith"
I am using rails 4.1.5 and ruby 2.0.0
Something that one needs once in a while and forgets about in the meantime:
How to remove blank or nil elements from an array
[1, “”, 2, “hello”, nil].reject(&:blank?)
gives
[1,2,”hello”]
all the credits go to
http://stackoverflow.com/questions/5878697/how-do-i-remove-blank-elements-from-an-array
and user ajahongir