Skip to content

Commit

Permalink
Updated to Rails 4 and Added jQuery masonry
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Nov 5, 2013
1 parent 334ae06 commit 418a23c
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 147 deletions.
8 changes: 5 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ ruby '2.0.0'
# Application gems
gem 'rails', '4.0.0'
gem 'jquery-rails'
gem 'devise'
gem 'devise', '~> 3.1.1'
gem 'simple_form', '~> 3.0.0.rc'
gem "paperclip", "~> 3.0"
gem 'aws-sdk'
gem "masonry-rails", '~> 0.2.0'
gem 'faker'
gem 'will_paginate', '3.0.3'
gem 'bootstrap-will_paginate'
Expand All @@ -32,9 +33,10 @@ gem 'uglifier', '>= 1.3.0'
gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass', branch: '3'

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '1.1.1'
gem 'turbolinks'
gem 'jquery-turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '1.0.2'
gem 'jbuilder', '1.2'

group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
Expand Down
17 changes: 12 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.6.3)
devise (3.1.0)
devise (3.1.1)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 3.2.6, < 5)
Expand All @@ -67,15 +67,20 @@ GEM
i18n (~> 0.5)
hike (1.2.3)
i18n (0.6.5)
jbuilder (1.0.2)
jbuilder (1.2.0)
activesupport (>= 3.0.0)
jquery-rails (3.0.4)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
jquery-turbolinks (2.0.1)
railties (>= 3.1.0)
turbolinks
json (1.8.0)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
masonry-rails (0.2.0)
rails
mime-types (1.25)
minitest (4.7.5)
multi_json (1.8.0)
Expand Down Expand Up @@ -162,10 +167,12 @@ DEPENDENCIES
bootstrap-sass!
bootstrap-will_paginate
coffee-rails (~> 4.0.0)
devise
devise (~> 3.1.1)
faker
jbuilder (= 1.0.2)
jbuilder (= 1.2)
jquery-rails
jquery-turbolinks
masonry-rails (~> 0.2.0)
paperclip (~> 3.0)
pg
protected_attributes
Expand All @@ -175,6 +182,6 @@ DEPENDENCIES
sdoc
simple_form (~> 3.0.0.rc)
sqlite3
turbolinks (= 1.1.1)
turbolinks
uglifier (>= 1.3.0)
will_paginate (= 3.0.3)
3 changes: 2 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
//
//= require jquery
//= require jquery_ujs
//= require jquery.masonry.min.js
//= require bootstrap
//= require jquery.turbolinks
//= require turbolinks
//= require masonry/jquery.masonry
//= require_tree .
7 changes: 5 additions & 2 deletions app/assets/javascripts/pins.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/

jQuery ->
# jQuery Masonry code here
$ ->
$('#pins').imagesLoaded ->
$('#pins').masonry itemSelector: ".box"
$('#pins').masonry
iitemSelector: '.box'
isFitWidth: true

# Added Pagination Code here
if $('.pagination').length
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require 'masonry/transitions'
*= require_tree .
*/
4 changes: 4 additions & 0 deletions app/assets/stylesheets/bootstrap_and_customization.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ body{
padding-top: 1px;
}

.center {
text-align: center;
}

.navbar-brand {
font-weight: bold;
}
Expand Down
13 changes: 13 additions & 0 deletions app/assets/stylesheets/pins.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Place all the styles related to the Pins controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

#pins {
margin: 0 auto;
}

.box {
margin: 5px;
width: 240px;
}

.box img {
width: 100%;
}
12 changes: 6 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
#protect_from_forgery with: :exception
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?

protected
protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :email, :current_password, :password, :password_confirmation) }
end
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:name, :email, :password, :password_confirmation) }
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:name, :email, :current_password, :password, :password_confirmation) }
end

end
26 changes: 10 additions & 16 deletions app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
class PinsController < ApplicationController
before_filter :authenticate_user!, except: [:index]
before_filter :authenticate_user!, except: [:index, :show]
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_action :correct_user, only: [:edit, :update, :destroy]

# GET /pins
# GET /pins.json
def index
# With pagination from will_paginate gem
@pins = Pin.order("created_at desc").page(params[:page]).per_page(20)
Expand All @@ -15,8 +14,6 @@ def index
end
end

# GET /pins/1
# GET /pins/1.json
def show
@pin = Pin.find(params[:id])
respond_to do |format|
Expand All @@ -26,25 +23,21 @@ def show
end
end

# GET /pins/new
def new
@pin = current_user.pins.new
@pin = current_user.pins.build

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

# GET /pins/1/edit
def edit
@pin = current_user.pins.find(params[:id])
end

# POST /pins
# POST /pins.json
def create
@pin = current_user.pins.new(params[:pin])
@pin = current_user.pins.build(params[:pin])

respond_to do |format|
if @pin.save
Expand All @@ -57,8 +50,6 @@ def create
end
end

# PATCH/PUT /pins/1
# PATCH/PUT /pins/1.json
def update
@pin = current_user.pins.find(params[:id])

Expand All @@ -73,8 +64,6 @@ def update
end
end

# DELETE /pins/1
# DELETE /pins/1.json
def destroy
@pin = current_user.pins.find(params[:id])
@pin.destroy
Expand All @@ -90,8 +79,13 @@ def set_pin
@pin = Pin.find(params[:id])
end

def correct_user
@pin = current_user.pins.find_by(id: params[:id])
redirect_to pins_path, notice: "Not authorized to edit this pin" if @pin.nil?
end

# Never trust parameters from the scary internet, only allow the white list through.
def pin_params
params.require(:pin).permit(:description)
params.require(:pin).permit(:description, :image)
end
end
2 changes: 1 addition & 1 deletion app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Pin < ActiveRecord::Base
content_type: { content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'] },
size: { less_than: 5.megabytes }
belongs_to :user
has_attached_file :image, :styles => { :medium => "300x300>" }
has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100" }

def image_remote_url=(url_value)
self.image = URI.parse(url_value) unless url_value.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, #:recoverable,
devise :database_authenticatable, :registerable, #:recoverable,
:rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :provider, :uid, :as => [:default, :admin]

Expand Down
40 changes: 27 additions & 13 deletions app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
<h2>Change your password</h2>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h1>Change your password</h1>
</div>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="form-group">
<%= f.label :password, "New password" %>
<%= f.password_field :password, class: "form-control", :autofocus => true %>
</div>

<div><%= f.label :password, "New password" %><br />
<%= f.password_field :password, :autofocus => true %></div>
<div class="form-group">
<%= f.label :password_confirmation, "Confirm new password" %>
<%= f.password_field :password_confirmation %>
</div>

<div><%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation %></div>

<div><%= f.submit "Change my password" %></div>
<% end %>

<%= render "devise/shared/links" %>
<div class="form-group">
<%= f.submit "Change my password", class: "btn btn-primary" %>
</div>
<% end %>
</div>
<div class="panel-footer">
<%= render "devise/shared/links" %>
</div>
</div>
32 changes: 22 additions & 10 deletions app/views/devise/passwords/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
<h2>Forgot your password?</h2>
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-title">
<h1>Forgot your password?</h1>
</div>
</div>
<div class="panel-body">
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>

<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: "form-control", :autofocus => true %>
</div>

<div><%= f.label :email %><br />
<%= f.email_field :email, :autofocus => true %></div>

<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>

<%= render "devise/shared/links" %>
<div class="form-group">
<%= f.submit "Send me reset password instructions", class: "btn btn-primary" %>
</div>
<% end %>
</div>
<div class="panel-footer">
<%= render "devise/shared/links" %>
</div>
</div>
Loading

0 comments on commit 418a23c

Please sign in to comment.