Skip to content

Commit

Permalink
Go back to using :name instead of first and last
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil Gehani committed Sep 18, 2013
1 parent 22e9a27 commit 9618747
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 14 deletions.
8 changes: 6 additions & 2 deletions app/controllers/pins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class PinsController < ApplicationController
before_action :set_pin, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: [:index]

# GET /pins
# GET /pins.json
Expand All @@ -14,17 +15,18 @@ def show

# GET /pins/new
def new
@pin = Pin.new
@pin = current_user.pins.new
end

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

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

respond_to do |format|
if @pin.save
Expand All @@ -40,6 +42,7 @@ def create
# PATCH/PUT /pins/1
# PATCH/PUT /pins/1.json
def update
@pin = current_user.pins.find(params[:id])
respond_to do |format|
if @pin.update(pin_params)
format.html { redirect_to @pin, notice: 'Pin was successfully updated.' }
Expand All @@ -54,6 +57,7 @@ def update
# DELETE /pins/1
# DELETE /pins/1.json
def destroy
@pin = current_user.pins.find(params[:id])
@pin.destroy
respond_to do |format|
format.html { redirect_to pins_url }
Expand Down
3 changes: 3 additions & 0 deletions app/models/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ class Pin < ActiveRecord::Base
attr_accessible :description

validates :description, presence: true

belongs_to :user
validates :user_id, presence: true
end
4 changes: 3 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class User < ActiveRecord::Base
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, #:recoverable,
:rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :provider, :uid, :as => [:default, :admin]
attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :first_name, :last_name, :provider, :uid, :as => [:default, :admin]

has_many :pins, :dependent => :destroy

end
5 changes: 3 additions & 2 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, class: 'form-horizontal' }) do |f| %>
<%= f.error_notification %>

<%= f.input :first_name %>
<%= f.input :last_name %>
<%#= f.input :first_name %>
<%#= f.input :last_name %>
<%= f.input :name %>
<%= f.input :email %>
<%= f.input :password, label: "New Password", autocomplete: "off" %>
<%= f.input :password_confirmation, label: "New Password Confirmation", autocomplete: "off" %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>
<%= f.error_notification %>

<%= f.input :first_name %>
<%= f.input :last_name %>
<%#= f.input :first_name %>
<%#= f.input :last_name %>
<%# - how do I show the concatenation of first_name and last_name here %>
<%= f.input :name %>
<%= f.input :email, placeholder: '[email protected]' %>
<%= f.input :password, placeholder: 'hint: no special characters' %>
<%= f.input :password_confirmation, placeholder: 're-type your password' %>
Expand Down
2 changes: 0 additions & 2 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

<%= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name), html: { class: 'form-horizontal'}) do |f| %>

<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :email, placeholder: '[email protected]' %>
<%= f.input :password, placeholder: 'hint: no special characters' %>
<%= f.input :remember_me, as: :boolean %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/pins/_pin.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<tr>
<td><%= pin.description %></td>
<td><%= link_to 'Show', pin %></td>
<td><%= link_to 'Edit', edit_pin_path(pin) %></td>
<td><%= link_to 'Destroy', pin, method: :delete, data: { confirm: 'Are you sure?' } %></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>
<% end %>
</tr>
9 changes: 7 additions & 2 deletions app/views/pins/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
<p>
<%= @pin.description %>
</p>
<%= link_to 'Edit', edit_pin_path(@pin) %> |
<%= link_to 'Back', pins_path %>
<p>
<%= @pin.user.name %>
</p>
<% if current_user == @pin.user %>
<%= link_to 'Edit', edit_pin_path(@pin) %> |
<% end %>
<%= link_to 'Back', pins_path %>
</div>
</div>
</div>
6 changes: 6 additions & 0 deletions db/migrate/20130917205250_add_user_id_to_pins.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddUserIdToPins < ActiveRecord::Migration
def change
add_column :pins, :user_id, :integer
add_index :pins, :user_id
end
end
5 changes: 5 additions & 0 deletions db/migrate/20130918001115_add_name_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddNameToUser < ActiveRecord::Migration
def change
add_column :users, :name, :string
end
end
6 changes: 5 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130917193701) do
ActiveRecord::Schema.define(version: 20130918001115) do

create_table "pins", force: true do |t|
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "user_id"
end

add_index "pins", ["user_id"], name: "index_pins_on_user_id"

create_table "users", force: true do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
Expand All @@ -34,6 +37,7 @@
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "name"
end

add_index "users", ["email"], name: "index_users_on_email", unique: true
Expand Down

0 comments on commit 9618747

Please sign in to comment.