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
def full_title(page_title) | |
base_title = "Ruby on Rails Tutorial Sample App" | |
if page_title.empty? | |
base_title | |
else | |
"#{base_title} | #{page_title}" | |
end | |
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
#Displays the current date but repeat x times | |
def display_time(how_many_times) | |
p = how_many_times.to_i | |
return p.times {puts Time.now.strftime("%m/%d/%y")} | |
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
user_input = "foo,bar,you,know".split(',') # We use split to make an array from user input | |
user_input.count # this will display 4 because we store 4 values in our array | |
# Now we use the temp array sort method | |
user_input.sort | |
# To save the values back to the array you need to use ! | |
user_input.sort! |
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
<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org' %> |
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
<!--The render command is used by rails to call shims and render them inside of your views--> | |
<!--shims have to be named the following _shimname.html.erb--> | |
<%= render 'layouts/header' %> |
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
# Creating better Routes. In rails you match the URI to the controller | |
# and then the action within the controller, this allows you to make bases URLs | |
# This creates a route that can also be referenced within code as the following | |
# contact_path = /contact | |
# contact_url = http://localhost/contact/ | |
match '/contact', to 'static_pages#contact' |
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
#To set the root of your app delete the index.html file within the | |
#public folder then use the below | |
root to: 'static_pages#home' |
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
# My first application test file using RSPEC and Capybara | |
# Here at the top we are defining the subject which is just pages. | |
# pages is the normal object that we would call before like pages.have_content | |
require 'spec_helper' | |
describe "Static pages" do | |
subject { page } |
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
# We use the gem annotate so that we annotate our models in development | |
# After creating your model run "bundle exec annotate --position before" | |
gem 'annotate', '~> 2.5.0' |
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
# You can define any model in the singular like User | |
# this should match the DB table users in the plural form | |
# then you can access that as a model as the following object | |
# When you want the first user in the DB table | |
user = User.first | |
# Then you can access the attributes by specifying the column | |
puts user.name |
OlderNewer