Class names are CamelCase
.
Methods and variables are snake_case
.
Methods with a ?
suffix will return a boolean.
$(document).ready(() => { | |
console.log('ready!'); | |
$("i#tweet-icon").on("click", () => { | |
let quote = $.trim($("#quote").text()); | |
window.open(`https://twitter.com/intent/tweet?text=${quote}`); | |
}); | |
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?'; |
$(document).ready(() => { | |
//Create a tweet function | |
function tweetQuote() { | |
window.open(`https://twitter.com/intent/tweet?text=${data.quoteText}`); | |
} | |
$("#tweet-icon").on("click", tweetQuote); | |
};//end of getRandomQuote | |
$("#quote-button").on("click", getRandomQuote); |
$(document).ready(() => { | |
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?'; | |
let getRandomQuote = () => { | |
$.getJSON(`${endpoint}`, (data) => { | |
$("#quote").html(`<i class="fas fa-quote-left"></i> ${data.quoteText} <i class="fas fa-quote-right"></i>`); | |
//Checking if the quote does not have an author | |
if (data.quoteAuthor !== "") { | |
$("#quote-author").html(`${data.quoteAuthor} at <a href="${data.quoteLink}" target="_blank" class="card-link">forismatic</a>`); |
$(document).ready(() => { | |
console.log('ready!'); | |
$("i#tweet-icon").on("click", () => { | |
let quote = $.trim($("#quote").text()); | |
window.open(`https://twitter.com/intent/tweet?text=${quote}`); | |
}); | |
});// end of document.ready |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | |
<!-- Bootstrap CSS --> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" | |
crossorigin="anonymous"> |
$(document).ready(() => { | |
console.log('ready!'); | |
$("i#tweet-icon").on("click", () => { | |
let quote = $.trim($("#quote").text()); | |
window.open(`https://twitter.com/intent/tweet?text=${quote}`); | |
}); | |
let endpoint = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=jsonp&jsonp=?'; |
=Navigating= | |
visit('/projects') | |
visit(post_comments_path(post)) | |
=Clicking links and buttons= | |
click_link('id-of-link') | |
click_link('Link Text') | |
click_button('Save') | |
click('Link Text') # Click either a link or a button | |
click('Button Value') |
class UsersController < ApplicationController | |
after_action :notify_slack, only: [:create, :update, :destroy] | |
before_action :set_user, only: [:show, :edit, :update, :destroy] | |
def index | |
@users = User.all | |
end | |
def show | |
end |
The Rails REST implementation dictates the default seven actions for your controllers, but frequently we want to share functionality across multiple actions or even across controllers. Controller filters are the easiest way to do that.
There are three types of filters implemented in Rails:
before_filter
runs before the controller actionafter_filter
runs after the controller action