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
class Ability | |
include CanCan::Ability | |
def initialize(user) | |
user ||= User.new # guest user (not logged in) | |
can :manage, User, id: user.id | |
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
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 |
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
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" |
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
<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> |
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
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 |
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
<%= 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> |
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
<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"> |
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
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 |
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
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}%") |
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
<!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> |
NewerOlder