Skip to content

Commit

Permalink
Add jQuery with Masonry
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcockerham committed Jun 6, 2013
1 parent acd606e commit e54f7b4
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.masonry.min.js
//= require bootstrap
//= require_tree .
3 changes: 3 additions & 0 deletions app/assets/javascripts/jobs.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
4 changes: 4 additions & 0 deletions app/assets/javascripts/pins.js.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

jQuery ->
$('#pins').imagesLoaded ->
$('#pins').masonry itemSelector: ".box"
26 changes: 26 additions & 0 deletions app/assets/stylesheets/styles.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,30 @@ body {
a {
color: $gray;
}
}

/* Required for jQuery Masonry */

.box {
margin: 5px;
padding: 5px;
font-size: 11px;
line-height: 1.4em;
float: left;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
box-shadow: 1px 1px 10px #444;
width: 214px;
}

.box img {
width: 100%;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}

.description {
margin: 10px 0 5px;
}
92 changes: 92 additions & 0 deletions app/controllers/jobs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
class JobsController < ApplicationController
before_filter :authenticate_user!

# GET /jobs
# GET /jobs.json
def index
@jobs = Job.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @jobs }
end
end

# GET /jobs/1
# GET /jobs/1.json
def show
@job = Job.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @job }
end
end

# GET /jobs/new
# GET /jobs/new.json
def new
@job = current_user.jobs.new
#@job = Job.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @job }
end
end

# GET /jobs/1/edit
def edit
@job = Job.find(params[:id])
end

# POST /jobs
# POST /jobs.json
def create
@job = current_user.jobs.new(params[:job])
#@job = Job.new(params[:job])

respond_to do |format|
if @job.user.hirer
if @job.save
format.html { redirect_to @job, notice: 'Job was successfully created.' }
format.json { render json: @job, status: :created, location: @job }
else
format.html { render action: "new" }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
else
format.html { redirect_to @job, notice: 'Only HR members can post jobs.' }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end

# PUT /jobs/1
# PUT /jobs/1.json
def update
@job = Job.find(params[:id])

respond_to do |format|
if @job.update_attributes(params[:job])
format.html { redirect_to @job, notice: 'Job was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @job.errors, status: :unprocessable_entity }
end
end
end

# DELETE /jobs/1
# DELETE /jobs/1.json
def destroy
@job = Job.find(params[:id])
@job.destroy

respond_to do |format|
format.html { redirect_to jobs_url }
format.json { head :no_content }
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class PinsController < ApplicationController
# GET /pins
# GET /pins.json
def index
@pins = Pin.all
@pins = Pin.order("created_at desc")
#@pins = Pin.all

# @pins = current_user.pins.all
# if @pins.empty?
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/jobs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module JobsHelper
end
18 changes: 18 additions & 0 deletions app/models/job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Job < ActiveRecord::Base
attr_accessible :description, :title

belongs_to :user

validates :description, presence: true, :length => { :maximum => 1000 }
validates :title, presence: true
validates :user_id, presence: true

#validates @job.user.hirer = true
#with_options :if => :is_hirer? do |hirer|
# hirer.validates :password, :length => { :minimum => 10 }
#hirer.validates :email, :presence => true
#end

#validates :hirer, :inclusion => { :in => [true, false] }
#validates :hirer, presence: true #(user.hirer = true)
end
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :hirer
# attr_accessible :title, :body

has_many :pins
has_many :pins, :dependent => :destroy
has_many :jobs, :dependent => :destroy
end
11 changes: 11 additions & 0 deletions app/views/jobs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= simple_form_for(@job, html: { class: "form-horizontal"}) do |f| %>
<%= f.error_notification %>

<%= f.input :title %>
<%= f.input :description, as: :text, input_html: { rows: "10" } %>


<div class="form-actions">
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
7 changes: 7 additions & 0 deletions app/views/jobs/_job.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<tr>
<td><%= job.title %></td>
<td><%= job.description %></td>
<td><%= link_to 'Show', job %></td>
<td><%= link_to 'Edit', edit_job_path(job) %></td>
<td><%= link_to 'Destroy', job, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
6 changes: 6 additions & 0 deletions app/views/jobs/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing job</h1>

<%= render 'form' %>

<%= link_to 'Show', @job %> |
<%= link_to 'Back', jobs_path %>
21 changes: 21 additions & 0 deletions app/views/jobs/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>Job Listings</h1>

<table class="table table-striped">
<thead>
<tr>
<th>Title</th>
<th>Description</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<%= render @jobs %>
</tbody>
</table>

<br />

<%= link_to 'New Job', new_job_path %>
5 changes: 5 additions & 0 deletions app/views/jobs/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New job</h1>

<%= render 'form' %>

<%= link_to 'Back', jobs_path %>
14 changes: 14 additions & 0 deletions app/views/jobs/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="span6 offset3">
<div class="well">
<p>
<%= @job.title %>
</p>
<p>
<%= @job.description %>
</p>
<%= link_to 'Edit', edit_job_path(@job) %> |
<%= link_to 'Back', jobs_path %>
</div>
</div>
</div>
3 changes: 2 additions & 1 deletion app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
<% end %>

<% if user_signed_in? && current_user.hirer %>
<li><%= link_to "Post a Job", job_post_path %></li>
<li><%= link_to "Post a Job", new_job_path %></li>
<% end %>
<!-- .nav, .navbar-search, .navbar-form, etc -->
</ul>
<ul class='nav pull-right'>
<% if user_signed_in? %>
<li><%= link_to "Add +", new_pin_path %></li>
<li><%= link_to "Edit Profile", edit_user_registration_path %></li>
<li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
<% else %>
Expand Down
24 changes: 16 additions & 8 deletions app/views/pins/_pin.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<tr>
<td><%= image_tag pin.image(:medium) %></td>
<td><%= pin.description %></td>
<td><%= link_to 'Show', pin %></td>
<% if current_user == pin.user %>
<td><%= link_to 'Edit', edit_pin_path(pin) %></td>
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<div class="box">
<%= link_to (image_tag pin.image(:medium)), pin %>
<p class="description">
<%= pin.description %>
</p>
<p>
<strong>
Posted by <%= pin.user.name %>
</strong>
</p>
<% if current_user == pin.user %>
<p>
<%= link_to 'Edit', edit_pin_path(pin) %>
<%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<% end %>
</tr>
</div>
24 changes: 3 additions & 21 deletions app/views/pins/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
<h1>Listing pins</h1>

<table class="table table-striped">
<thead>
<tr>
<th>Image</th>
<th>Description</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<%= render @pins %>
</tbody>
</table>

<br />

<%= link_to 'New Pin', new_pin_path %>
<div id="pins">
<%= render @pins %>
</div>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Omrails::Application.routes.draw do

resources :jobs


resources :pins


Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20130606015341_create_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateJobs < ActiveRecord::Migration
def change
create_table :jobs do |t|
t.string :title
t.string :description

t.timestamps
end
end
end
6 changes: 6 additions & 0 deletions db/migrate/20130606030659_add_user_id_to_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUserIdToJobs < ActiveRecord::Migration
def change
add_column :jobs, :user_id, :integer
add_index :jobs, :user_id
end
end
12 changes: 11 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,17 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20130604110107) do
ActiveRecord::Schema.define(:version => 20130606030659) do

create_table "jobs", :force => true do |t|
t.string "title"
t.string "description"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "user_id"
end

add_index "jobs", ["user_id"], :name => "index_jobs_on_user_id"

create_table "pins", :force => true do |t|
t.string "description"
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/jobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html

one:
title: MyString
description: MyString

two:
title: MyString
description: MyString
Loading

0 comments on commit e54f7b4

Please sign in to comment.