Skip to content

Instantly share code, notes, and snippets.

View mdunbavan's full-sized avatar

Mark Dunbavan mdunbavan

View GitHub Profile
@mdunbavan
mdunbavan / _books_form.html.erb
Created September 18, 2014 09:27
Rails gallery create on a book
# form for books#create page
<%= simple_form_for(@book, :html => { :multipart => true }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.file_field :jacket_cover %>
<%= f.input :title %>
<%= f.input :synopsis, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<%= f.input :body, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<%= f.input :age %>
@mdunbavan
mdunbavan / book.rb
Created September 22, 2014 14:18
authors save post
class Book < ActiveRecord::Base
has_attached_file :jacket_cover, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :jacket_cover, :content_type => /\Aimage\/.*\Z/
validates :jacket_cover, :title, :slug, :synopsis, :body, :age, :publisher, presence: true
validates_uniqueness_of :title
extend FriendlyId
friendly_id :title, use: [:slugged, :finders]
@mdunbavan
mdunbavan / author.rb
Last active August 29, 2015 14:06
Saving authors on books
class Author < ActiveRecord::Base
has_many :books, dependent: :destroy
accepts_nested_attributes_for :books
#validates_uniqueness_of :name
end
@mdunbavan
mdunbavan / _form.html.erb
Created September 23, 2014 14:26
ajax submit
// Inside books/form
<%= simple_form_for(@book, :remote => true, :authenticity_token => true, :html => { :multipart => true }) do |f| %>
<%= f.error_notification %>
<div class="inputs">
<%= f.file_field :jacket_cover %>
<%= f.input :title %>
<%= f.input :synopsis, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
<%= f.input :body, :as => :ckeditor, :label => false, :input_html => { :ckeditor => { :toolbar => 'Full', :height => 400 } } %>
@mdunbavan
mdunbavan / book_form.html.erb
Created September 29, 2014 15:08
Images to gallery upload params
# form to add images to the gallery
<%= f.simple_fields_for :gallery do |builder| %>
<%= builder.input :name %>
<%= render 'galleries/form', :f => builder %>
<% end %>
@mdunbavan
mdunbavan / books_controller.rb
Created September 30, 2014 11:11
book gallery
class BooksController < ApplicationController
def show
@gallery = @book.gallery
end
def new
@book = Book.new
@author = Author.new
@school = School.new
@book.build_author
@mdunbavan
mdunbavan / _school_fields.html.erb
Last active August 29, 2015 14:07
school check
<div class="inputs nested-fields">
<%= f.input :school_name %>
<%= f.input :address %>
<%= link_to_remove_association '', f, :class => 'fa fa-minus' %>
</div>
<div>
<label for="sort-by">Sort by</label>
<select id="sort-by">
<option value="manual">Featured</option>
<option value="price-ascending">Price: Low to High</option>
<option value="price-descending">Price: High to Low</option>
<option value="title-ascending">A-Z</option>
<option value="title-descending">Z-A</option>
<option value="created-ascending">Oldest to Newest</option>
<option value="created-descending">Newest to Oldest</option>
@mdunbavan
mdunbavan / log.txt
Last active August 29, 2015 14:14
Code for devise users
Started GET "/users/" for 127.0.0.1 at 2015-02-02 13:07:58 +0000
Processing by UsersController#index as JSON
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = 42 ORDER BY "users"."id" ASC LIMIT 1
DEPRECATION WARNING: Relation#all is deprecated. If you want to eager-load a relation, you can call #load (e.g. `Post.where(published: true).load`). If you want to get an array of records from a relation, you can call #to_a (e.g. `Post.where(published: true).to_a`). (called from index at /Freelance/Current Projects/Pop Up Hub Project/build/popup-hub/app/controllers/users_controller.rb:4)
User Load (1.8ms) SELECT "users".* FROM "users" ORDER BY created_at DESC
Rendered users/index.html.erb within layouts/application (2.9ms)
Role Load (0.7ms) SELECT "roles".* FROM "roles" WHERE "roles"."id" = $1 ORDER BY "roles"."id" ASC LIMIT 1 [["id", 2]]
Rendered partials/_admin_menu.html.erb (0.3ms)
Rendered partials/_components.html.erb (1.5ms)
Rendered partials/_footer.html.erb (0.2ms)
@mdunbavan
mdunbavan / Gruntfile.js
Created May 22, 2015 10:28
Assemble setup for posts and listing posts
'use strict';
// # Globbing
// for performance reasons we're only matching one level down:
// '<%= config.src %>/templates/pages/{,*/}*.hbs'
// use this if you want to match all subfolders:
// '<%= config.src %>/templates/pages/**/*.hbs'
module.exports = function(grunt) {