Permalink
Browse files

store who created a list and show each user's lists

  • Loading branch information...
1 parent da48605 commit dcc4ee05ddd11e895c181e690abf0b10a9a02144 @mikeymicrophone committed Apr 18, 2012
View
@@ -39,13 +39,13 @@ gem 'jquery-rails'
# To use debugger
group :development do
- # gem 'sqlite3'
- gem 'mysql2'
+ gem 'sqlite3'
+ # gem 'mysql2'
gem 'ruby-debug19', :require => 'ruby-debug'
end
group :production do
- gem 'pg'
+ # gem 'pg'
end
group :test do
View
@@ -95,11 +95,9 @@ GEM
httparty (>= 0.4.3)
multi_json (1.2.0)
multi_xml (0.4.2)
- mysql2 (0.3.11)
net-ssh (2.1.4)
nokogiri (1.4.5)
orm_adapter (0.0.7)
- pg (0.13.2)
polyglot (0.3.3)
rack (1.3.6)
rack-cache (1.2)
@@ -148,7 +146,8 @@ GEM
sprockets (2.0.3)
hike (~> 1.2)
rack (~> 1.0)
- tilt (!= 1.3.0, ~> 1.1)
+ tilt (~> 1.1, != 1.3.0)
+ sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
@@ -177,10 +176,9 @@ DEPENDENCIES
fog
jquery-rails
kaminari
- mysql2
- pg
rails (= 3.1.3)
ruby-debug19
sass-rails (~> 3.1.5)
+ sqlite3
turn (= 0.8.2)
uglifier (>= 1.0.3)
@@ -40,7 +40,8 @@ def edit
# POST /lists
# POST /lists.json
def create
- @list = List.new(params[:list])
+ @list = List.new(params[:list]) # params[:list] = {:name => 'kittens'}
+ @list.user = current_user
respond_to do |format|
if @list.save
@@ -0,0 +1,6 @@
+class UsersController < ApplicationController
+ def show
+ @user = User.find(params[:id])
+ @lists = @user.lists
+ end
+end
View
@@ -1,4 +1,5 @@
class List < ActiveRecord::Base
has_many :listed_pictures, :order => "position"
has_many :pictures, :through => :listed_pictures
+ belongs_to :user
end
View
@@ -1,4 +1,5 @@
class User < ActiveRecord::Base
+ has_many :lists
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
@@ -1,17 +1,11 @@
-<h1>Listing lists</h1>
+<h1>All of the lists</h1>
<table>
- <tr>
- <th>Name</th>
- <th></th>
- <th></th>
- </tr>
<% @lists.each do |list| %>
<tr>
<td><%= link_to list.name, list %></td>
- <td><%= link_to 'Edit', edit_list_path(list) %></td>
- <td><%= link_to 'Destroy', list, confirm: 'Are you sure?', method: :delete %></td>
+ <td><%= link_to(list.user.email, user_path(list.user_id)) %></td>
</tr>
<% end %>
</table>
@@ -0,0 +1,7 @@
+<%= @user.email %><br>
+
+This user's lists are named:<br>
+
+<% @lists.each do |list| %>
+ <%= list.name %><br>
+<% end %>
View
@@ -4,28 +4,28 @@
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
- adapter: mysql2
- database: community_pics_development
- username: root
- password:
- host: localhost
+ # adapter: mysql2
+ # database: community_pics_development
+ # username: root
+ # password: medialabsql
+ # host: localhost
- # adapter: sqlite3
- # database: db/development.sqlite3
- # pool: 5
- # timeout: 5000
-
-# Warning: The database defined as "test" will be erased and
-# re-generated from your development database when you run "rake".
-# Do not set this db to the same as development or production.
-test:
adapter: sqlite3
- database: db/test.sqlite3
+ database: db/development.sqlite3
pool: 5
timeout: 5000
-production:
- adapter: sqlite3
- database: db/production.sqlite3
- pool: 5
- timeout: 5000
+# Warning: The database defined as "test" will be erased and
+# re-generated from your development database when you run "rake".
+# Do not set this db to the same as development or production.
+# test:
+# adapter: sqlite3
+# database: db/test.sqlite3
+# pool: 5
+# timeout: 5000
+#
+# production:
+# adapter: sqlite3
+# database: db/production.sqlite3
+# pool: 5
+# timeout: 5000
View
@@ -5,6 +5,8 @@
match 'logout' => 'devise/sessions#destroy', :as => 'logout'
end
+ resources :users
+
match 'facebook_login' => 'facebook#facebook_login'
resources :listed_pictures do
@@ -0,0 +1,8 @@
+class ListsHaveUserId < ActiveRecord::Migration
+ def up
+ add_column :lists, :user_id, :integer
+ end
+
+ def down
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120410141308) do
+ActiveRecord::Schema.define(:version => 20120417235846) do
create_table "listed_pictures", :force => true do |t|
t.integer "list_id"
@@ -28,6 +28,7 @@
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "user_id"
end
create_table "notes", :force => true do |t|

0 comments on commit dcc4ee0

Please sign in to comment.