Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #186 from MYDRY/feature/add-minimum-point-system
Browse files Browse the repository at this point in the history
Feature/add minimum point system
  • Loading branch information
tanacchi authored Dec 13, 2018
2 parents 3965a77 + 1069594 commit b7617c9
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/ideas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def create
@idea = topic.ideas.build(idea_params)
@idea.user_id = current_user.id
if @idea.save
@idea.user.change_point 5
flash[:success] = "アイデアを投稿しました"
view_context.spawn_new_idea_notice(topic)
redirect_to topic_path(topic)
Expand All @@ -49,6 +50,7 @@ def update
def destroy
@idea = Idea.find(params[:id])
@idea.destroy
@idea.user.change_point -5
flash[:success] = "アイデアを削除しました"
redirect_back fallback_location: topics_path
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/likes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def create
@idea = Idea.find(params[:idea_id])
like = current_user.likes.build(idea_id: @idea.id)
like.save
@idea.user.change_point 10
view_context.spawn_like_notice(@idea)
# flash[:success] = "いいねしました"
@idea.reload
Expand All @@ -15,6 +16,7 @@ def destroy
@idea = Idea.find(params[:id])
like = Like.find_by(idea_id: @idea.id, user_id: current_user.id)
like.destroy
@idea.user.change_point -10
# flash[:success] = "いいねを取り消しました"
@idea.reload
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def new
def create
@topic = current_user.topics.build(topic_params)
if @topic.save
@topic.user.change_point 5
flash[:success] = "トピックを投稿しました"
redirect_to @topic
else
Expand All @@ -49,6 +50,7 @@ def update
def destroy
@topic = Topic.find(params[:id])
@topic.destroy
@topic.user.change_point -5
flash[:success] = "トピックを削除しました"
redirect_back fallback_location: topics_path
end
Expand Down
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class User < ApplicationRecord
has_many :simple_mandals, dependent: :destroy

mount_uploader :image, ProfileImageUploader

def change_point(amount)
self.point += amount
self.save!
end
end
1 change: 1 addition & 0 deletions app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<li><%= link_to_unless_current user.name, user_path(id: user) %></li>
<!--<li><%= user.email %></li>-->
</div>
<%= user.point %> points <!--!!!!!!!!!!!!!!!!!!! EDIT HERE !!!!!!!!!!!!!!!!!!!-->
<% if user == current_user %>
<li> <%= link_to edit_user_path(id: user) do %>
<div style="float: right;"><span class="fa fa-edit fa-2x "></span> 編集</div>
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20181213071630_add_point_to_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPointToUser < ActiveRecord::Migration[5.2]
def change
add_column :users, :point, :integer, default: 100
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_11_14_001505) do
ActiveRecord::Schema.define(version: 2018_12_13_071630) do

create_table "comments", force: :cascade do |t|
t.text "body"
Expand Down Expand Up @@ -193,6 +193,7 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "admin", default: false
t.integer "point", default: 100
end

create_table "words", force: :cascade do |t|
Expand Down

0 comments on commit b7617c9

Please sign in to comment.