Skip to content

Instantly share code, notes, and snippets.

View Phoenix23A's full-sized avatar

Phoenix23A

  • Switzerland
View GitHub Profile
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
can :manage, User, id: user.id
end
end
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
ActiveRecord::Schema.define(version: 20160203161649) do
create_table "comments", force: :cascade do |t|
t.integer "user_id"
t.text "body"
t.integer "rating"
t.integer "product_id"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["product_id"], name: "index_comments_on_product_id"
<table>
<tbody>
<tr>
<td><p>You have received a new contact form message. The contents of the message are:</p></td>
</tr>
<tr>
<td><p><%= @message %></p></td>
</tr>
</tbody>
</table>
class UserMailer < ActionMailer::Base
default from: "from@example.com"
def contact_form(email, name, message)
@message = message
mail(:from => email,
:to => 'your-email@example.com',
:subject => "A new contact form message from #{name}")
end
end
<%= form_for(@product) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<% @products.each_with_index do |product, i| %>
<li data-target="#carousel-example-generic" data-slide-to="<%= i %>" class="<%= 'active' if i == 0 %>"></li>
<% end %>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
class OrdersController < ApplicationController
#skip_before_filter :verify_authenticity_token MAKES it vulnurable for attacks
protect_from_forgery with: :null_session
respond_to :json, :html
def index
@orders = Order.all.to_json(:include => [{:product => {:only => :name}}, {:user => {:only => :email}}])
respond_with @orders
end
lass ProductsController < ApplicationController
before_action :set_product, only: [:show, :edit, :update, :destroy]
respond_to :json, :html
# GET /products
# GET /products.json
def index
if params[:q]
search_term = params[:q]
@products = Product.where("name LIKE ?", "%#{search_term}%")
<!DOCTYPE html>
<html>
<head>
<title>Nameofapp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>