Skip to content

Instantly share code, notes, and snippets.

View jdibiccari's full-sized avatar

Janel diBiccari jdibiccari

View GitHub Profile
#Utilize the helper variable
helper.truncate("Rails is a magical thing", length: 11)
#=>"Rails is..."
helper.pluralize(2, "sandbox")
#=> "2 sandboxes"
#Or the app variable...(don't mind me as I switch domains)
pond = Pond.last
app.pond_path(pond)
#Example with one route and a view
#To install: gem install camping
#To run file: camping camping_example.rb
Camping.goes :App
module App::Controllers
class Index
def get
render :motto
<%-Artist.list_alphabetically.each do |artist|-%>
<li><a href="artists/<%=artist.url%>"><%=artist.name%></a> song count: <%=artist.songs_count%></li>
<%-end-%>
@jdibiccari
jdibiccari / erb_with_trim.rb
Last active August 29, 2015 14:02
blog_post_5
=begin
Modifier options for trim_mode
___________________________________________________________
% enables Ruby code processing for lines beginning with %
<> omit newline for lines starting with <% and ending in %>
> omit newline for lines ending in %>
- omit blank lines ending in -%>
=end
@jdibiccari
jdibiccari / erb_obj.rb
Created June 10, 2014 04:04
blog_post_5
template = ERB.new(File.read("lib/views/genres.html.erb"))
<!-- Example of an each loop -->
<ul>
<%Artist.list_alphabetically.each do |artist|%>
<li><a href="artists/<%=artist.url%>"><%=artist.name%></a> song count: <%=artist.songs_count%></li>
<%end%>
</ul>
<!-- Example of an if statement -->
<h4><%=artist.name%> - <%=artist.songs_count%>
<%if artist.songs_count > 1%>
@jdibiccari
jdibiccari / mod_2.js
Created May 27, 2014 13:22
blog_post_4
Number.prototype.negMod = function(n) {
return ((this%n)+n)%n;
};
//Where 'this' is the number we are taking modulus of
@jdibiccari
jdibiccari / mod.js
Created May 27, 2014 13:16
blog_post_4
var shift = -5 % 4
//=> shift = -1
@jdibiccari
jdibiccari / structs_2.rb
Last active August 29, 2015 14:01
blog_post_3
Submarine = Struct.new(:captain, :sub_name) do
def destination?
puts "Headed to the Aquadome"
end
end
scimitar2 = Submarine.new("Lauren", "Scimitar 2")
scimitar2.captain
#=> Lauren
scimitar2.destination?
@jdibiccari
jdibiccari / structs.rb
Last active August 29, 2015 14:01
blog_post_3
Submarine = Struct.new(:captain, :sub_name)
scimitar = Submarine.new("Janel", "Scimitar")
#=> <struct Submarine captain="Janel", sub_name="Scimitar>