rails_interact 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +23 -0
- data/Rakefile +32 -0
- data/app/controllers/interact/admin/abuses_controller.rb +54 -0
- data/app/controllers/interact/admin/attitudes_controller.rb +55 -0
- data/app/controllers/interact/admin/base_controller.rb +3 -0
- data/app/controllers/interact/admin/comments_controller.rb +42 -0
- data/app/controllers/interact/admin/stars_controller.rb +55 -0
- data/app/controllers/interact/attitudes_controller.rb +81 -0
- data/app/controllers/interact/base_controller.rb +3 -0
- data/app/controllers/interact/comments_controller.rb +59 -0
- data/app/controllers/interact/my/abuses_controller.rb +46 -0
- data/app/controllers/interact/my/attitudes_controller.rb +70 -0
- data/app/controllers/interact/my/base_controller.rb +3 -0
- data/app/controllers/interact/my/comments_controller.rb +60 -0
- data/app/controllers/interact/my/stars_controller.rb +43 -0
- data/app/models/interact/abuse.rb +5 -0
- data/app/models/interact/attitude.rb +5 -0
- data/app/models/interact/comment.rb +6 -0
- data/app/models/interact/ext/commentable.rb +16 -0
- data/app/models/interact/ext/like.rb +19 -0
- data/app/models/interact/ext/user.rb +10 -0
- data/app/models/interact/model/abuse.rb +13 -0
- data/app/models/interact/model/attitude.rb +69 -0
- data/app/models/interact/model/comment.rb +58 -0
- data/app/models/interact/model/star.rb +13 -0
- data/app/models/interact/star.rb +5 -0
- data/app/models/interact.rb +11 -0
- data/app/views/application/_interact_nav.html.erb +13 -0
- data/app/views/interact/admin/abuses/_form.html.erb +4 -0
- data/app/views/interact/admin/abuses/_index/_index_tbody.html.erb +7 -0
- data/app/views/interact/admin/abuses/_index/_index_thead.html.erb +7 -0
- data/app/views/interact/admin/abuses/_show_table.html.erb +16 -0
- data/app/views/interact/admin/attitudes/_form.html.erb +4 -0
- data/app/views/interact/admin/attitudes/index.html.erb +50 -0
- data/app/views/interact/admin/attitudes/show.html.erb +26 -0
- data/app/views/interact/admin/comments/_filter_form.html.erb +8 -0
- data/app/views/interact/admin/comments/_filter_table.html.erb +11 -0
- data/app/views/interact/admin/comments/_form.html.erb +3 -0
- data/app/views/interact/admin/comments/index.html.erb +49 -0
- data/app/views/interact/admin/comments/show.html.erb +22 -0
- data/app/views/interact/admin/stars/_form.html.erb +3 -0
- data/app/views/interact/admin/stars/_search_form.html.erb +7 -0
- data/app/views/interact/admin/stars/index.html.erb +48 -0
- data/app/views/interact/admin/stars/show.html.erb +22 -0
- data/app/views/interact/comments/_comment.json.jbuilder +17 -0
- data/app/views/interact/comments/index.json.jbuilder +2 -0
- data/app/views/interact/comments/show.json.jbuilder +1 -0
- data/app/views/interact/my/attitudes/_form.html.erb +4 -0
- data/app/views/interact/my/attitudes/_search_form.html.erb +7 -0
- data/app/views/interact/my/attitudes/dislike.js.erb +1 -0
- data/app/views/interact/my/attitudes/index.html.erb +41 -0
- data/app/views/interact/my/attitudes/like.js.erb +1 -0
- data/app/views/interact/my/attitudes/show.html.erb +10 -0
- data/app/views/interact/my/comments/_comment.html.erb +27 -0
- data/app/views/interact/my/comments/_comment.json.jbuilder +17 -0
- data/app/views/interact/my/comments/_form.html.erb +4 -0
- data/app/views/interact/my/comments/create.js.erb +5 -0
- data/app/views/interact/my/comments/index.html.erb +41 -0
- data/app/views/interact/my/comments/index.json.jbuilder +2 -0
- data/app/views/interact/my/comments/show.html.erb +10 -0
- data/app/views/interact/my/comments/show.json.jbuilder +1 -0
- data/app/views/interact/my/stars/_star.json.jbuilder +8 -0
- data/app/views/interact/my/stars/index.json.jbuilder +2 -0
- data/app/views/interact/my/stars/show.json.jbuilder +1 -0
- data/config/locales/en.notify.yml +11 -0
- data/config/locales/zh.notify.yml +11 -0
- data/config/routes.rb +45 -0
- data/lib/rails_interact/config.rb +9 -0
- data/lib/rails_interact/engine.rb +20 -0
- data/lib/rails_interact.rb +2 -0
- metadata +156 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bbd729071aeda737f4679c6bee127c1a2462669efe6655760ba190ae92536ef
|
4
|
+
data.tar.gz: 5cbfd10f8d82f5952fa1a6d81f4f3214fbe8502322456e427f8cedde8bbb9a5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42311eedc9f4c70db37b002c351edbe670c612f8770820c1283fe3d6429d5092615cde934dcb3688a4d2be88c9e7bca8cb3dd9be32b508d773d8d59957eadabc
|
7
|
+
data.tar.gz: 6c5e321c214d3a30d7cb2c3a0e4ff4f59be3bfe955f7e29c58458c9393a76ba154f7af724d8d9fb6a702f3b33a29743c7c906fb8a79cf219bad3f7830e28e285
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2019-Present Mingyuan Qin <mingyuan0715@foxmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# RailsInteract
|
2
|
+
Utils for comment, like/dislike, report abuse;
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'rails_interact'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
Contribution directions go here.
|
21
|
+
|
22
|
+
## License
|
23
|
+
遵循 [MIT协议](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsComment'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Interact::Admin::AbusesController < Interact::Admin::BaseController
|
2
|
+
before_action :set_abuse, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@abuses = Abuse.page(params[:page])
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@abuse = Abuse.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@abuse = Abuse.new(abuse_params)
|
14
|
+
|
15
|
+
if @abuse.save
|
16
|
+
redirect_to admin_abuses_url
|
17
|
+
else
|
18
|
+
render :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if @abuse.update(abuse_params)
|
30
|
+
redirect_to admin_abuses_url
|
31
|
+
else
|
32
|
+
render :edit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
@abuse.destroy
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def set_abuse
|
42
|
+
@abuse = Abuse.find(params[:id])
|
43
|
+
end
|
44
|
+
|
45
|
+
def abuse_params
|
46
|
+
params.fetch(:abuse, {}).permit(
|
47
|
+
:abusement,
|
48
|
+
:state,
|
49
|
+
:note,
|
50
|
+
:user
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Interact::Admin::AttitudesController < Interact::Admin::BaseController
|
2
|
+
before_action :set_attitude, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@attitudes = Attitude.page(params[:page])
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@attitude = Attitude.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@attitude = Attitude.new(attitude_params)
|
14
|
+
|
15
|
+
if @attitude.save
|
16
|
+
redirect_to admin_attitudes_url, notice: 'Attitude was successfully created.'
|
17
|
+
else
|
18
|
+
render :new
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
if @attitude.update(attitude_params)
|
30
|
+
redirect_to admin_attitudes_url, notice: 'Attitude was successfully updated.'
|
31
|
+
else
|
32
|
+
render :edit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def destroy
|
37
|
+
@attitude.destroy
|
38
|
+
redirect_to admin_attitudes_url, notice: 'Attitude was successfully destroyed.'
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def set_attitude
|
43
|
+
@attitude = Attitude.find(params[:id])
|
44
|
+
end
|
45
|
+
|
46
|
+
def attitude_params
|
47
|
+
params.fetch(:attitude, {}).permit(
|
48
|
+
:user_id,
|
49
|
+
:opinion,
|
50
|
+
:attitudinal_type,
|
51
|
+
:attitudinal_id
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
class Interact::Admin::CommentsController < Interact::Admin::BaseController
|
2
|
+
before_action :set_comment, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
q_params = {}.with_indifferent_access
|
6
|
+
q_params.merge! params.permit(:commentable_type, :commentable_id)
|
7
|
+
@comments = Comment.default_where(q_params).page(params[:page])
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
def edit
|
14
|
+
end
|
15
|
+
|
16
|
+
def update
|
17
|
+
if @comment.update(comment_params)
|
18
|
+
redirect_to comments_url, notice: 'Comment was successfully updated.'
|
19
|
+
else
|
20
|
+
render :edit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
@comment.destroy
|
26
|
+
redirect_to comments_url, notice: 'Comment was successfully destroyed.'
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def set_comment
|
31
|
+
@comment = Comment.find(params[:id])
|
32
|
+
end
|
33
|
+
|
34
|
+
def comment_params
|
35
|
+
params.fetch(:comment, {}).permit(
|
36
|
+
:title,
|
37
|
+
:content,
|
38
|
+
:state
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
class Interact::Admin::StarsController < Interact::Admin::BaseController
|
2
|
+
before_action :set_star, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
q_params = params.permit(:user_id, :starred_type, :starred_id)
|
6
|
+
@stars = Star.default_where(q_params).page(params[:page])
|
7
|
+
end
|
8
|
+
|
9
|
+
def new
|
10
|
+
@star = Star.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@star = Star.new(star_params)
|
15
|
+
|
16
|
+
if @star.save
|
17
|
+
redirect_to admin_stars_url, notice: 'Star was successfully created.'
|
18
|
+
else
|
19
|
+
render :new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def show
|
24
|
+
end
|
25
|
+
|
26
|
+
def edit
|
27
|
+
end
|
28
|
+
|
29
|
+
def update
|
30
|
+
if @star.update(star_params)
|
31
|
+
redirect_to admin_stars_url, notice: 'Star was successfully updated.'
|
32
|
+
else
|
33
|
+
render :edit
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy
|
38
|
+
@star.destroy
|
39
|
+
redirect_to admin_stars_url, notice: 'Star was successfully destroyed.'
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def set_star
|
44
|
+
@star = Star.find(params[:id])
|
45
|
+
end
|
46
|
+
|
47
|
+
def star_params
|
48
|
+
params.fetch(:star, {}).permit(
|
49
|
+
:user_id,
|
50
|
+
:starred_type,
|
51
|
+
:starred_id
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
class Interact::AttitudesController < Interact::BaseController
|
2
|
+
before_action :set_attitude, only: [:create, :like, :dislike, :cancel]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@attitudes = Attitude.page(params[:page])
|
6
|
+
|
7
|
+
render json: @attitudes
|
8
|
+
end
|
9
|
+
|
10
|
+
def new
|
11
|
+
@attitude = Attitude.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@attitude.opinion = params[:opinion] || attitude_params[:opinion]
|
16
|
+
|
17
|
+
if @attitude.save
|
18
|
+
render json: @attitude.as_json(root: true), status: :ok
|
19
|
+
else
|
20
|
+
process_errors(@attitude)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def like
|
25
|
+
@attitude.opinion = 'liked'
|
26
|
+
|
27
|
+
if @attitude.save
|
28
|
+
render json: @attitude.as_json(root: true), status: :created
|
29
|
+
else
|
30
|
+
process_errors(@attitude)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def dislike
|
35
|
+
@attitude.opinion = 'disliked'
|
36
|
+
|
37
|
+
if @attitude.save
|
38
|
+
render json: @attitude.as_json(root: true), status: :accepted
|
39
|
+
else
|
40
|
+
process_errors(@attitude)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def cancel
|
45
|
+
if @attitude.opinion == 'liked'
|
46
|
+
@attitude.opinion = 'like_canceled'
|
47
|
+
elsif @attitude.opinion == 'disliked'
|
48
|
+
@attitude.opinion = 'dislike_canceled'
|
49
|
+
end
|
50
|
+
|
51
|
+
if @attitude.save
|
52
|
+
render json: @attitude.as_json(root: true), status: :accepted
|
53
|
+
else
|
54
|
+
process_errors(@attitude)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def set_attitude
|
60
|
+
@attitude = Attitude.find_or_initialize_by(
|
61
|
+
attitudinal_type: params[:attitudinal_type].classify,
|
62
|
+
attitudinal_id: params[:attitudinal_id],
|
63
|
+
user_id: current_user.id
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
def attitude_params
|
68
|
+
params.fetch(:attitude, {}).permit(
|
69
|
+
:opinion
|
70
|
+
)
|
71
|
+
end
|
72
|
+
|
73
|
+
def growth_entity_type
|
74
|
+
params[:attitudinal_type]
|
75
|
+
end
|
76
|
+
|
77
|
+
def growth_entity_id
|
78
|
+
params[:attitudinal_id]
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Interact::CommentsController < Interact::BaseController
|
2
|
+
before_action :set_comment, only: [:show, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
q_params = {}
|
6
|
+
q_params.merge! params.permit(:commentable_type, :commentable_id)
|
7
|
+
@comments = Comment.default_where(q_params).page(params[:page]).per(params[:per])
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
def create
|
14
|
+
@comment = Comment.new(comment_params)
|
15
|
+
|
16
|
+
if @comment.save
|
17
|
+
render :show, status: :created
|
18
|
+
else
|
19
|
+
process_errors(@comment)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def update
|
24
|
+
if @comment.update(comment_params)
|
25
|
+
render 'show'
|
26
|
+
else
|
27
|
+
render json: @comment.errors, status: :unprocessable_entity
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def destroy
|
32
|
+
@comment.destroy
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def set_comment
|
37
|
+
@comment = Comment.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
def comment_params
|
41
|
+
params.fetch(:comment, {}).permit(
|
42
|
+
:title,
|
43
|
+
:content,
|
44
|
+
:star_count,
|
45
|
+
).merge(
|
46
|
+
commentable_type: params[:commentable_type].classify,
|
47
|
+
commentable_id: params[:commentable_id]
|
48
|
+
).merge(user_id: current_user.id)
|
49
|
+
end
|
50
|
+
|
51
|
+
def growth_entity_type
|
52
|
+
params[:commentable_type]
|
53
|
+
end
|
54
|
+
|
55
|
+
def growth_entity_id
|
56
|
+
params[:commentable_id]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class Interact::My::AbusesController < Interact::My::BaseController
|
2
|
+
before_action :set_abuse, only: [:show, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@abuses = Abuse.page(params[:page])
|
6
|
+
|
7
|
+
render json: @abuses
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
render json: @abuse
|
12
|
+
end
|
13
|
+
|
14
|
+
def create
|
15
|
+
@abuse = Abuse.new(abuse_params)
|
16
|
+
|
17
|
+
if @abuse.save
|
18
|
+
render json: @abuse.as_json(root: true), status: :created
|
19
|
+
else
|
20
|
+
render json: @abuse.errors, status: :unprocessable_entity
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
if @abuse.update(abuse_params)
|
26
|
+
render json: @abuse
|
27
|
+
else
|
28
|
+
render json: @abuse.errors, status: :unprocessable_entity
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
@abuse.destroy
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def abuse_params
|
38
|
+
params.fetch(:abuse, {}).permit(
|
39
|
+
:note
|
40
|
+
).merge(
|
41
|
+
abusement_id: params[:abusement_id],
|
42
|
+
abusement_type: params[:abusement_type].classify,
|
43
|
+
user_id: current_user&.id
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
class Interact::My::AttitudesController < Interact::My::BaseController
|
2
|
+
before_action :set_attitude, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@attitudes = Attitude.page(params[:page])
|
6
|
+
end
|
7
|
+
|
8
|
+
def like
|
9
|
+
@attitude = Attitude.find_or_initialize_by(
|
10
|
+
attitudinal_type: params[:attitudinal_type],
|
11
|
+
attitudinal_id: params[:attitudinal_id],
|
12
|
+
user_id: current_user.id
|
13
|
+
)
|
14
|
+
@attitude.opinion = 'liked'
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
if @attitude.save
|
18
|
+
format.js { @attitudinal = @attitude.attitudinal }
|
19
|
+
format.json { render json: @attitude.as_json(root: true), status: :created }
|
20
|
+
else
|
21
|
+
format.js
|
22
|
+
format.json { process_errors(@attitude) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def dislike
|
28
|
+
@attitude = Attitude.find_or_initialize_by(
|
29
|
+
attitudinal_type: params[:attitudinal_type],
|
30
|
+
attitudinal_id: params[:attitudinal_id],
|
31
|
+
user_id: current_user.id
|
32
|
+
)
|
33
|
+
@attitude.opinion = 'disliked'
|
34
|
+
|
35
|
+
respond_to do |format|
|
36
|
+
if @attitude.save
|
37
|
+
format.js
|
38
|
+
format.json { render json: @attitude.as_json(root: true), status: :accepted }
|
39
|
+
else
|
40
|
+
format.js
|
41
|
+
format.json { process_errors(@attitude) }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def show
|
47
|
+
end
|
48
|
+
|
49
|
+
def edit
|
50
|
+
end
|
51
|
+
|
52
|
+
def update
|
53
|
+
if @attitude.update(attitude_params)
|
54
|
+
redirect_to my_attitudes_url, notice: 'Attitude was successfully updated.'
|
55
|
+
else
|
56
|
+
render :edit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def destroy
|
61
|
+
@attitude.destroy
|
62
|
+
redirect_to my_attitudes_url, notice: 'Attitude was successfully destroyed.'
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
def set_attitude
|
67
|
+
@attitude = Attitude.find(params[:id])
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Interact::My::CommentsController < Interact::My::BaseController
|
2
|
+
before_action :set_comment, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
@comments = Comment.page(params[:page])
|
6
|
+
end
|
7
|
+
|
8
|
+
def new
|
9
|
+
@comment = Comment.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@comment = Comment.new(comment_params)
|
14
|
+
|
15
|
+
respond_to do |format|
|
16
|
+
if @comment.save
|
17
|
+
format.js
|
18
|
+
format.html { redirect_to my_comments_url, notice: 'Comment was successfully created.' }
|
19
|
+
else
|
20
|
+
format.js
|
21
|
+
format.html { render :new }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def show
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
end
|
31
|
+
|
32
|
+
def update
|
33
|
+
if @comment.update(comment_params)
|
34
|
+
redirect_to my_comments_url, notice: 'Comment was successfully updated.'
|
35
|
+
else
|
36
|
+
render :edit
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def destroy
|
41
|
+
@comment.destroy
|
42
|
+
redirect_to my_comments_url, notice: 'Comment was successfully destroyed.'
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def set_comment
|
47
|
+
@comment = Comment.find(params[:id])
|
48
|
+
end
|
49
|
+
|
50
|
+
def comment_params
|
51
|
+
params.fetch(:comment, {}).permit(
|
52
|
+
:title,
|
53
|
+
:content,
|
54
|
+
:score
|
55
|
+
).merge(
|
56
|
+
params.permit(:commentable_type, :commentable_id)
|
57
|
+
).merge(user_id: current_user.id)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Interact::My::StarsController < Interact::My::BaseController
|
2
|
+
before_action :set_star, only: [:create, :toggle, :destroy]
|
3
|
+
|
4
|
+
def index
|
5
|
+
q_params = {}
|
6
|
+
q_params.merge! params.permit(:starred_type)
|
7
|
+
@stars = Star.default_where(q_params).page(params[:page]).per(params[:per])
|
8
|
+
end
|
9
|
+
|
10
|
+
def create
|
11
|
+
if @star.save
|
12
|
+
render json: @star.as_json(root: true), status: :created
|
13
|
+
else
|
14
|
+
render json: @star.errors, status: :unprocessable_entity
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def destroy
|
19
|
+
if @star.persisted? && @star.destroy
|
20
|
+
render json: {}, status: :ok
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def toggle
|
25
|
+
if @star.new_record? && @star.save
|
26
|
+
render json: @star, status: :created
|
27
|
+
elsif @star.persisted? && @star.destroy
|
28
|
+
render json: {}, status: :ok
|
29
|
+
else
|
30
|
+
render json: @star.errors, status: :unprocessable_entity
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def set_star
|
36
|
+
@star = Star.find_or_initialize_by(
|
37
|
+
starred_type: params[:starred_type].classify,
|
38
|
+
starred_id: params[:starred_id],
|
39
|
+
user_id: current_user.id
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|