This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%-Artist.list_alphabetically.each do |artist|-%> | |
<li><a href="artists/<%=artist.url%>"><%=artist.name%></a> song count: <%=artist.songs_count%></li> | |
<%-end-%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template = ERB.new(File.read("lib/views/genres.html.erb")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Number.prototype.negMod = function(n) { | |
return ((this%n)+n)%n; | |
}; | |
//Where 'this' is the number we are taking modulus of |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var shift = -5 % 4 | |
//=> shift = -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submarine = Struct.new(:captain, :sub_name) | |
scimitar = Submarine.new("Janel", "Scimitar") | |
#=> <struct Submarine captain="Janel", sub_name="Scimitar> |