We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: The open source social networking platform in Ruby on Rails from the author of RailsSpace
Homepage: http://insoshi.com
Clone URL: git://github.com/insoshi/insoshi.git
Person has_many photos
Michael Hartl (author)
Thu Feb 21 13:25:43 -0800 2008
commit  ba54c3645101555e90ca5db094a5460ae8f33085
tree    23b83db88b3d1bc181a34a9bee14908bb30ef50e
parent  26772b4ac48d2670fbd5eb6f8e03c0632dc33d0c
...
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
0
@@ -1,2 +1,117 @@
0
 class PhotosController < ApplicationController
0
+
0
+ # before_filter :login_required
0
+ # before_filter :correct_user_required, :only => [ :edit, :update, :destroy ]
0
+ # before_filter :cancellation, :only => [ :create ]
0
+ #
0
+ #
0
+ # def index
0
+ # @person = Person.find_by_hashed_id(params[:person_id])
0
+ # @photos = @person.photos
0
+ #
0
+ # respond_to do |format|
0
+ # format.html # index.html.erb
0
+ # format.xml { render :xml => @photos }
0
+ # end
0
+ # end
0
+
0
+ # # GET /photos/new
0
+ # # GET /photos/new.xml
0
+ # def new
0
+ # @photo = Photo.new
0
+ #
0
+ # respond_to do |format|
0
+ # format.html # new.html.erb
0
+ # format.xml { render :xml => @photo }
0
+ # end
0
+ # end
0
+ #
0
+ # # GET /photos/1/edit
0
+ # def edit
0
+ # @photo = Photo.find_by_hashed_id(params[:id])
0
+ # @display_photo = @photo
0
+ # end
0
+ #
0
+ # # POST /photos
0
+ # # POST /photos.xml
0
+ # def create
0
+ # if params[:photo][:uploaded_data].blank?
0
+ # flash[:error] = "Please choose an image"
0
+ # redirect_to new_photo_url and return
0
+ # end
0
+ #
0
+ # @photo = Photo.new(params[:photo].merge(
0
+ # { :person => current_person,
0
+ # :primary => current_person.photos.empty? }))
0
+ #
0
+ # respond_to do |format|
0
+ # if @photo.save
0
+ # format.html { redirect_to(edit_person_path(current_person)) }
0
+ # format.xml { render :xml => @photo, :status => :created, :location => @photo }
0
+ # else
0
+ # format.html { render :action => "new" }
0
+ # format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
0
+ # end
0
+ # end
0
+ # end
0
+ #
0
+ # # PUTUT /photos/1
0
+ # # PUT /photos/1.xml
0
+ # def update
0
+ # @photo = Photo.find_by_hashed_id(params[:id])
0
+ # redirect_to edit_person_url(current_person) and return if @photo.nil?
0
+ # # This should only have one entry, but be paranoid.
0
+ # # Also, subtract out current photo in case some idiot puts to this
0
+ # # by hand.
0
+ # @old_primary = current_person.photos.select(&:primary?) - [@photo]
0
+ #
0
+ # respond_to do |format|
0
+ # if @photo.update_attributes(:primary => true)
0
+ # @old_primary.each { |p| p.update_attributes!(:primary => false) }
0
+ # format.html { redirect_to(edit_person_path(current_person)) }
0
+ # format.xml { head :ok }
0
+ # else
0
+ # format.html do
0
+ # flash[:error] = "Invalid image!"
0
+ # redirect_to home_url
0
+ # end
0
+ # format.xml { render :xml => @photo.errors, :status => :unprocessable_entity }
0
+ # end
0
+ # end
0
+ # end
0
+ #
0
+ # # DELETE /photos/1
0
+ # # DELETE /photos/1.xml
0
+ # def destroy
0
+ # @photo = Photo.find_by_hashed_id(params[:id])
0
+ # redirect_to edit_person_url(current_person) and return if @photo.nil?
0
+ # if @photo.primary?
0
+ # first_non_primary = current_person.photos.reject(&:primary?).first
0
+ # unless first_non_primary.nil?
0
+ # first_non_primary.update_attributes!(:primary => true)
0
+ # end
0
+ # end
0
+ # @photo.destroy
0
+ #
0
+ # respond_to do |format|
0
+ # format.html { redirect_to edit_person_url(current_person) }
0
+ # format.xml { head :ok }
0
+ # end
0
+ # end
0
+ #
0
+ # private
0
+ #
0
+ # def correct_user_required
0
+ # photo = Photo.find_by_hashed_id(params[:id])
0
+ # redirect_to edit_person_url(current_person) and return if photo.nil?
0
+ # unless photo.person == current_person
0
+ # redirect_to login_url
0
+ # end
0
+ # end
0
+ #
0
+ # def cancellation
0
+ # cancel = params[:commit] == "Cancel"
0
+ # redirect_to edit_person_url(current_person) if cancel
0
+ # end
0
 end
0
+
...
13
14
15
 
16
17
18
...
13
14
15
16
17
18
19
0
@@ -13,6 +13,7 @@ class Person < ActiveRecord::Base
0
   NUM_RECENT_MESSAGES = 4
0
   NUM_RECENTLY_VIEWED = 4
0
   
0
+ has_many :photos
0
   attr_accessor :password
0
   attr_accessible :email, :password, :password_confirmation, :name,
0
                   :description
...
25
26
27
 
 
 
 
 
 
 
 
28
29
30
...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
0
@@ -25,6 +25,14 @@ describe Person do
0
       u = create_person(:email => nil)
0
       u.errors.on(:email).should_not be_nil
0
     end
0
+
0
+ it "should have associated photos" do
0
+ @person.photos.should_not be_nil
0
+ end
0
+
0
+ it "should not currently have any photos" do
0
+ @person.photos.should be_empty
0
+ end
0
   end
0
 
0
   it 'resets password' do

Comments

    No one has commented yet.