Skip to content

Commit

Permalink
Added dropdown link, my pins view, and fixed endless scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Nov 6, 2013
1 parent 8c94e7d commit 0c0bc16
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 81 deletions.
26 changes: 1 addition & 25 deletions app/assets/stylesheets/styles.css.scss
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
/* Required for jQuery Masonry */
/* anything beginning with a . is a class and used in views as class = "blah" */

.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;
}

#view_paginate {
visibility: hidden;
}
}
38 changes: 7 additions & 31 deletions app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,20 @@ class PinsController < ApplicationController

def index
# With pagination from will_paginate gem
@pins = Pin.order("created_at desc").page(params[:page]).per_page(20)

@pins = Pin.all.order("created_at DESC").page(params[:page]).per_page(20)
respond_to do |format|
format.html # index.html.erb
format.json { render json: @pin }
#format.json { render json: @pins }
format.js
end
end

def show
@pin = Pin.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @pin }
format.js
end
end

def new
@pin = current_user.pins.build

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

def edit
Expand All @@ -38,39 +27,26 @@ def edit

def create
@pin = current_user.pins.build(params[:pin])

respond_to do |format|
if @pin.save
format.html { redirect_to @pin, notice: 'Pin was successfully created.' }
format.json { render action: 'show', status: :created, location: @pin }
redirect_to @pin, notice: 'Pin was successfully created.'
else
format.html { render action: 'new' }
format.json { render json: @pin.errors, status: :unprocessable_entity }
render action: 'new'
end
end
end

def update
@pin = current_user.pins.find(params[:id])

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

def destroy
@pin = current_user.pins.find(params[:id])
@pin.destroy
respond_to do |format|
format.html { redirect_to pins_url }
format.json { head :no_content }
end
redirect_to pins_url
end

private
Expand Down
1 change: 1 addition & 0 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Pin < ActiveRecord::Base
attr_accessible :description, :image, :image_remote_url
has_attached_file :image

validates :image, presence: true
validates :description, presence: true
validates :user_id, presence: true
validates_attachment :image, presence: true,
Expand Down
3 changes: 3 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class User < ActiveRecord::Base
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :provider, :uid, :as => [:default, :admin]

has_many :pins, :dependent => :destroy

validates :name, presence: true

acts_as_followable
acts_as_follower

Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, placeholder: '[email protected]', autofocus: true, class: "form-control" %>
<%= f.email_field :email, placeholder: '[email protected]', class: "form-control" %>
</div>

<div class="form-group">
Expand Down
16 changes: 11 additions & 5 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,19 @@
<% if user_signed_in? %>
<li>
<%= link_to new_pin_path do %>
<span class="glyphicon glyphicon-plus-sign"></span> New Pin
<span class="glyphicon glyphicon-plus-sign" ></span> New Pin
<% end %>
</li>
<li>
<%= link_to edit_user_registration_path do %>
<span class="glyphicon glyphicon-user"></span> Account Settings
<% end %>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><%= current_user.name %> <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<%= link_to edit_user_registration_path do %>
<span class="glyphicon glyphicon-user"></span> Account Settings
<% end %>
</li>
<li><%= link_to "My Pins", user_pins_path %></li>
</ul>
</li>
<li><%= link_to "Log out", destroy_user_session_path, method: :delete %></li>
<% else %>
Expand Down
12 changes: 5 additions & 7 deletions app/views/pages/_home.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<% unless user_signed_in? %>
<div class="jumbotron center">
<h1>Social Butterfly</h1>
<p>
<%= link_to "Sign up", new_user_registration_path, class: "btn btn-primary btn-lg" %>
<%= link_to "Log in", new_user_session_path, class: "btn btn-default btn-lg" %>
</p>
<h1>Social Butterfly</h1>
<p>
<%= link_to "Sign up", new_user_registration_path, class: "btn btn-primary btn-lg" %>
<%= link_to "Log in", new_user_session_path, class: "btn btn-default btn-lg" %>
</p>
</div>
<% end %>

30 changes: 20 additions & 10 deletions app/views/pins/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
<%= form_for @pin, html: { multipart: true } do |f| %>
<%# f.error_notification %>
<%# f.full_error :image_file_size, class: "alert alert-error" %>
<%# f.full_error :image_content_type, class: "alert alert-error" %>
<% if @pin.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@pin.errors.count, "error") %> prohibited this pin from being saved:</h2>

<ul>
<% @pin.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<%# f.input :image_remote_url, label: "or enter a URL" %>
<%# f.input :description, as: :text, input_html: { rows: "3" } %>

<div class="form-group">
<%= f.label :image_remote_url %>
<%= f.file_field :image_remote_url, class: "form-control" %>
<%= f.label "Enter the image URL" %>
<%= f.text_field :image_remote_url, class: "form-control" %>
</div>

<div class="form-group">
<%= f.label :image %>
<%= f.file_field :image, class: "form-control" %>
</div>


<div class="form-group">
<%= f.label :description %>
<%= f.text_field :description, class: "form-control" %>
</div>

<div class="form-group">
<%= f.submit class: "btn btn-primary" %>
</div>
<% end %>
<% end %>
6 changes: 4 additions & 2 deletions app/views/pins/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<%= render 'pages/home' unless user_signed_in? %>
<div id="pins" class="transitions-enabled">
<%= render @pins %>
</div>
</div>

<div id="view_paginate">
<%= will_paginate @pins %>
<div class="center">
<%= will_paginate @pins %>
</div>
</div>
8 changes: 8 additions & 0 deletions app/views/pins/user_pins.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%# render includes partials that begin with _*.html.erb %>
<%# means look in pages subfolder for _home.html.erb %>
<%= render 'pages/home' unless user_signed_in? %>
<div id="pins" class="transitions-enabled">
<% if user_signed_in? %>
<%= render current_user.pins %>
<% end %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
devise_for :users
get 'about' => 'pages#about'
root :to => 'pins#index'
get 'user_pins' => 'pins#user_pins'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".

Expand Down

0 comments on commit 0c0bc16

Please sign in to comment.