Skip to content

Commit e502538

Browse files
author
Christopher Talib
authored
Merge pull request #265 from tosdr/add-more-than-one-point
added another submit button on the form page so that the redirect goe…
2 parents cbf8d53 + c139094 commit e502538

File tree

4 files changed

+22
-41
lines changed

4 files changed

+22
-41
lines changed

app/controllers/points_controller.rb

Lines changed: 14 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
class PointsController < ApplicationController
22
before_action :set_point, only: [:show, :edit,:featured, :update, :destroy]
33

4-
# before_action :set_service
5-
# before_action :set_topic
6-
74
def index
85
@points = Point.all
96
if @query = params[:query]
107
@points = Point.search_points_by_multiple(@query)
11-
128
end
139
end
1410

1511
def new
1612
@point = Point.new
1713
@services = Service.all
1814
@topics = Topic.all
19-
# if current_user
20-
# @point = Point.new
21-
# else
22-
# flash[:notice] = "Please log in before adding a point"
23-
# redirect_to new_user_path
24-
# end
2515
end
2616

2717
def create
2818
@point = Point.new(point_params)
2919
@point.user = current_user
30-
# need to instantiate the services ?
31-
# @point.topic = @topic
32-
# @point.service = @service
33-
# if yes, TODO: create the setting private methods
34-
if @point.save
35-
redirect_to points_path
36-
flash[:notice] = "You created a point!"
37-
else
38-
render :new
20+
if params[:only_create]
21+
if @point.save
22+
redirect_to points_path
23+
flash[:notice] = "You created a point!"
24+
else
25+
render :new
26+
end
27+
elsif params[:create_add_another]
28+
if @point.save
29+
redirect_to new_point_path
30+
flash[:notice] = "You created a point! Feel free to add another."
31+
else
32+
render :new
33+
end
3934
end
4035
end
4136

@@ -44,7 +39,6 @@ def edit
4439

4540
def show
4641
puts @point.id
47-
# @comments = @point.comments
4842
@comments = Comment.where(point_id: @point.id)
4943
end
5044

@@ -74,30 +68,15 @@ def featured
7468
end
7569
end
7670

77-
# def upvote
78-
# @vote = Vote.new(point_id: @point.id, user_id: current_user.id)
79-
# if @vote.save
80-
# respond_to do |format|
81-
# format.html { redirect_to point_path(@point)}
82-
# format.js
83-
# end
84-
# end
85-
# end
86-
8771
def user_points
8872
@points = current_user.points
8973
if @query = params[:query]
9074
@points = Point.search_points_by_multiple(@query)
9175
end
9276
end
9377

94-
9578
private
9679

97-
# def set_point_by_point_id
98-
# @point = Point.find(params[:point_id])
99-
# end
100-
10180
def set_point
10281
@point = Point.find(params[:id])
10382
end
@@ -106,10 +85,6 @@ def set_service
10685
@service = Service.find(params[:service_id])
10786
end
10887

109-
# def set_topic
110-
# @topic = Topic.find(params[:topic_id])
111-
# end
112-
11388
def point_params
11489
params.require(:point).permit(:title, :source, :status, :rating, :analysis, :topic_id, :service_id, :is_featured, :query)
11590
end

app/views/points/_form.html.erb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="form-login">
22
<div class="row row-form">
33
<div class="point-form-text">
4-
<p>When submiting a contribution. You submit what we call a point. It's an analysis on one specific point of the ToS of the service you want to rate. All points have a rating from 1 to 10 and the class given to the service is the average of the all those points. See the <a href="/about#classification">about page</a> for more information.</p>
4+
<p>When submitting a contribution, you submit what we call a "point." It's an analysis on one specific aspect of the ToS of the service that you want to rate. All points have a rating from 1 to 10 and the class given to the service is the average of all those ratings. See the <a href="/about#classification">about page</a> for more information.</p>
55

66
<p>Each point submitted by a user has to be reviewed by a curator before being displayed on the website. You will recieve a message by email from the curator who reviewed your point.</p>
77
</div>
@@ -36,7 +36,8 @@
3636
<%= link_to "Back", :back, class: "btn btn-default" %>
3737
</div>
3838
<div class="form-actions col-xs-8 col-sm-4 col-sm-offset-6 col-md-3 col-md-offset-7">
39-
<%= f.submit class: 'btn btn-primary' %>
39+
<%= f.submit "Submit Point", name: "only_create", class: 'btn btn-primary' %>
40+
<%= f.submit "Submit Point + Add Another", name: "create_add_another", class: 'btn btn-primary' %>
4041
</div>
4142
</div>
4243
<% end %>

db/migrate/20171214143221_create_comments.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
class CreateComments < ActiveRecord::Migration[5.1]
22
def change
3+
drop_table :comments
34
create_table :comments do |t|
45
t.references :point, foreign_key: true
56
t.string :summary

db/schema.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@
8787
t.datetime "created_at", null: false
8888
t.datetime "updated_at", null: false
8989
t.string "grade"
90+
t.bigint "user_id"
91+
t.string "status"
9092
t.string "wikipedia"
9193
t.string "keywords"
9294
t.string "related"
9395
t.string "slug"
96+
t.index ["user_id"], name: "index_services_on_user_id"
9497
end
9598

9699
create_table "topics", force: :cascade do |t|
@@ -143,4 +146,5 @@
143146
add_foreign_key "points", "users"
144147
add_foreign_key "reasons", "points"
145148
add_foreign_key "reasons", "users"
149+
add_foreign_key "services", "users"
146150
end

0 commit comments

Comments
 (0)