Skip to content

Instantly share code, notes, and snippets.

View itzsaga's full-sized avatar
🍕

Seth itzsaga

🍕
View GitHub Profile
// Arrow Functions
// With multiple arguments
let arrowFunction = (arg1, arg2) => {
// Do Something
}
// With one argument
let arrowFunction = oneArg => {
// Do Something
}

Specifications for the Rails Assessment

Specs:

  • Using Ruby on Rails for the project
  • Include at least one has_many relationship (x has_many y e.g. User has_many Recipes)
  • Include at least one belongs_to relationship (x belongs_to y e.g. Post belongs_to User)
  • Include at least one has_many through relationship (x has_many y through z e.g. Recipe has_many Items through Ingredients)
  • The "through" part of the has_many through includes at least one user submittable attribute (attribute_name e.g. ingredients.quantity)
  • Include reasonable validations for simple model objects (list of model objects with validations e.g. User, Recipe, Ingredient, Item)
  • Include a class level ActiveRecord scope method (model object & class method name and URL to see the working feature e.g. User.most_recipes URL: /users/most_recipes)
new_person = { name: "Seth"
, age: 32
, height: 74
, weight: 155
, alive: true
}
# First try
config.omniauth :facebook, FB_APP_ID, FB_APP_SECRET
# Second try
config.omniauth :facebook, 'FB_APP_ID', 'FB_APP_SECRET'
# Third and correct try
config.omniauth :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET']
line_item = line_items.find_by(item_id: itemid)
if items.include?(line_item.try(:item))
has_one :current_cart, class_name: "Cart"
# before
def total
items.map { |item| item.price }.sum
end
# after rubocop linting
def total
items.map(&:price).sum
end
function truncateString(str, num) {
if (str.length <= num) {
return str;
} else if (num <=3) {
return str.slice(0, num) + "...";
} else {
return str.slice(0, num - 3) + "...";
}
}
<% @posts.each do |post| %>
<%= render :partial => "post", {:locals => {:post => post}} %>
<% end %>
<!-- OR -->
<%= render :partial => "post", :collection => @posts %>
<!-- OR -->
<%= f.fields_for :user_attributes, User.new do |u_fields| %>