Skip to content

Commit 54a213d

Browse files
author
Theresa
committed
Beautify collections
1 parent fae6041 commit 54a213d

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

app/controllers/collections_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def edit
2525
# POST /collections.json
2626
def create
2727
@collection = Collection.new(collection_params)
28+
@collection.user = current_user
2829

2930
respond_to do |format|
3031
if @collection.save
@@ -69,6 +70,6 @@ def set_collection
6970

7071
# Never trust parameters from the scary internet, only allow the white list through.
7172
def collection_params
72-
params.require(:collection).permit(:user_id)
73+
params.require(:collection).permit(:title)
7374
end
7475
end

app/views/collections/_form.html.erb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
</ul>
1111
</div>
1212
<% end %>
13-
1413
<div class="field">
15-
<%= f.label :user_id %><br>
16-
<%= f.text_field :user_id %>
14+
<%= f.label :title %><br>
15+
<%= f.text_field :title%>
1716
</div>
1817
<div class="actions">
19-
<%= f.submit %>
18+
<%= f.submit nil, class:'btn btn-primary' %>
2019
</div>
2120
<% end %>

app/views/collections/index.html.erb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
<p id="notice"><%= notice %></p>
22

3-
<h1>Listing Collections</h1>
3+
<h2>Your Collections <%= link_to 'New Collection', new_collection_path, class:'btn btn-success' %> </h2>
44

5-
<table>
5+
<table class="table">
66
<thead>
77
<tr>
8-
<th>User</th>
9-
<th colspan="3"></th>
8+
<th>Title</th>
9+
<th>Exercises</th>
10+
<th colspan="2">Actions</th>
1011
</tr>
1112
</thead>
1213

1314
<tbody>
1415
<% @collections.each do |collection| %>
15-
<tr>
16-
<td><%= collection.user %></td>
17-
<td><%= link_to 'Show', collection %></td>
18-
<td><%= link_to 'Edit', edit_collection_path(collection) %></td>
19-
<td><%= link_to 'Destroy', collection, method: :delete, data: { confirm: 'Are you sure?' } %></td>
20-
</tr>
16+
<% if collection.user === current_user %>
17+
<tr>
18+
<td><%= collection.title %></td>
19+
<% if collection.exercises %>
20+
<% collection.exercises.each do |exercise| %>
21+
<td><%= link_to exercise.title, exercise_path(exercise) %></td>
22+
<% end %>
23+
<% else%>
24+
<td> <%= 'No exercises added' %></td>
25+
<% end %>
26+
<td><%= link_to 'Edit', edit_collection_path(collection), class:'btn btn-warning btn-xs' %></td>
27+
<td><%= link_to 'Destroy', collection, method: :delete, data: { confirm: 'Are you sure?' }, class:'btn btn-danger btn-xs' %></td>
28+
</tr>
29+
<% end %>
2130
<% end %>
2231
</tbody>
2332
</table>
2433

2534
<br>
26-
27-
<%= link_to 'New Collection', new_collection_path %>

app/views/collections/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
<%= render 'form' %>
44

5-
<%= link_to 'Back', collections_path %>
5+
<%= link_to 'Back', :back, class: 'btn btn-default'%>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<p id="notice"><%= notice %></p>
22

33
<p>
4-
<strong>User:</strong>
5-
<%= @collection.user %>
4+
<strong>Collection:</strong>
5+
<%= @collection.title %>
66
</p>
77

8-
<%= link_to 'Edit', edit_collection_path(@collection) %> |
8+
<%= link_to 'Edit', edit_collection_path(@collection), class:'btn btn-warning' %> |
99
<%= link_to 'Back', collections_path %>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddTitleToCollection < ActiveRecord::Migration
2+
def change
3+
add_column :collections, :title, :string
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20160213230122) do
14+
ActiveRecord::Schema.define(version: 20160215215407) do
1515

1616
create_table "account_links", force: :cascade do |t|
1717
t.datetime "created_at", null: false
@@ -63,6 +63,7 @@
6363
t.integer "user_id"
6464
t.datetime "created_at", null: false
6565
t.datetime "updated_at", null: false
66+
t.string "title"
6667
end
6768

6869
add_index "collections", ["user_id"], name: "index_collections_on_user_id"

0 commit comments

Comments
 (0)