select2_helper 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +32 -0
- data/app/assets/javascripts/select2_helper.js.coffee +100 -0
- data/app/controllers/select2_controller.rb +25 -0
- data/app/models/concerns/select2_concern.rb +26 -0
- data/app/views/select2/results.json.jbuilder +5 -0
- data/app/views/select2/tags.json.jbuilder +5 -0
- data/config/routes.rb +4 -0
- data/lib/select2_helper.rb +9 -0
- data/lib/select2_helper/errors.rb +7 -0
- data/lib/select2_helper/version.rb +3 -0
- data/lib/tasks/select2_helper_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +16 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/pages_controller.rb +4 -0
- data/test/dummy/app/controllers/projects_controller.rb +58 -0
- data/test/dummy/app/controllers/tasks_controller.rb +58 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/project.rb +5 -0
- data/test/dummy/app/models/task.rb +5 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/pages/index.html.erb +37 -0
- data/test/dummy/app/views/projects/_form.html.erb +31 -0
- data/test/dummy/app/views/projects/edit.html.erb +6 -0
- data/test/dummy/app/views/projects/index.html.erb +27 -0
- data/test/dummy/app/views/projects/new.html.erb +5 -0
- data/test/dummy/app/views/projects/show.html.erb +14 -0
- data/test/dummy/app/views/tasks/_form.html.erb +29 -0
- data/test/dummy/app/views/tasks/edit.html.erb +6 -0
- data/test/dummy/app/views/tasks/index.html.erb +29 -0
- data/test/dummy/app/views/tasks/new.html.erb +5 -0
- data/test/dummy/app/views/tasks/show.html.erb +19 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +85 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +83 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +59 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/migrate/20140527180322_create_projects.rb +10 -0
- data/test/dummy/db/migrate/20140527180427_create_tasks.rb +11 -0
- data/test/dummy/db/schema.rb +36 -0
- data/test/dummy/log/development.log +9895 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/pages_controller_test.rb +9 -0
- data/test/dummy/test/controllers/projects_controller_test.rb +49 -0
- data/test/dummy/test/controllers/tasks_controller_test.rb +49 -0
- data/test/dummy/test/factories/projects.rb +8 -0
- data/test/dummy/test/factories/tasks.rb +9 -0
- data/test/dummy/test/fixtures/projects.yml +9 -0
- data/test/dummy/test/fixtures/tasks.yml +11 -0
- data/test/dummy/test/models/project_test.rb +7 -0
- data/test/dummy/test/models/task_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/142e7fd2c85a87d270e4fd271e945642 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/20a2742a642444d35da6761f661b3fe0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/25819886b1b5d849b15d78a77bfae37d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/35fbb4453edc7ae6ac6704f1002f32df +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/44d54dc4f4f5f01ad21b0c3b86be2913 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/47519dd4ec1de6cedccedec8561ab352 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/501a695a5f241c549cac4109a7f21e35 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/574b5665e77ea1b5e37666852db46012 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/59dbe4fb498319628373091eae217b85 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6670943499444e8b67b53f147c9691c8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/73214d449277f121ae99674373349b9c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/74f0b8d7fd1d954cef0b5a6a1d46d4e6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/86ea3c481cf2fa8c2cbc7736a6d2f578 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/8e83573f6393d13316efb7d02d1ce2f0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/93ec664048bf1c019655ba77098c83c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9dec80587c00d47a7ef1f8dd7bb35198 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/b45b717a170260b00060c40280c4ed41 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c4d0bdedab06899031ceb8170acbfda4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d5ff021bac42e2a975828c6d5c347278 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ded9139cab353ae56b68a46be15a9ced +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f5a52a7d62f9c8b29b911bab47331da7 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/select2_helper_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +315 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5e63c14036148ee61d0a703756067b28fe932089
|
4
|
+
data.tar.gz: 12669bacb6a632b360f16c4f0e8f163a2e5db074
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0393f25053e29e92d76ea316840789ff5d65a540d22d77c678e657f8ab2656e04481e5ec59987f98f257ba535818d6f3cfeff3f0946b5ae51bb552e7fc1fa0a
|
7
|
+
data.tar.gz: 9aeeb5e949e41f6060e54162b475a62492ab123a20758c79853dcabec74254a4abbeb5bd1aadc63cb650ccc110d9251f68beb3b4ad2c7de57a9f99cda2e3faa7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
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/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 = 'Select2Helper'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << 'lib'
|
26
|
+
t.libs << 'test'
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
t.verbose = false
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
task default: :test
|
@@ -0,0 +1,100 @@
|
|
1
|
+
$(document).on 'ready page:change', () ->
|
2
|
+
jQuery.fn.extend
|
3
|
+
select2_single: (params) ->
|
4
|
+
this.each () ->
|
5
|
+
if $(this).data('child-field') && child_field = $($(this).data('child-field'))
|
6
|
+
$(this).on 'change', () ->
|
7
|
+
record_id = this.value
|
8
|
+
where_obj = {}
|
9
|
+
where_obj[child_field.data('foreign-key')] = record_id
|
10
|
+
child_field.select2_single
|
11
|
+
ajax:
|
12
|
+
data: (term, page) ->
|
13
|
+
term: term
|
14
|
+
page: page
|
15
|
+
where: where_obj
|
16
|
+
model: $(this).data('model')
|
17
|
+
column: $(this).data('column')
|
18
|
+
.trigger('change')
|
19
|
+
default_params =
|
20
|
+
width: '100%'
|
21
|
+
initSelection: (element, callback) ->
|
22
|
+
callback
|
23
|
+
id: element.val()
|
24
|
+
text: element.data('init') || ''
|
25
|
+
ajax:
|
26
|
+
url: '/select2/results'
|
27
|
+
dataType: 'json'
|
28
|
+
data: (term, page) ->
|
29
|
+
term: term
|
30
|
+
page: page
|
31
|
+
model: $(this).data('model')
|
32
|
+
column: $(this).data('column')
|
33
|
+
results: (data, page) -> data
|
34
|
+
this.select2 $.extend(true, default_params, params)
|
35
|
+
select2_multiple: (params) ->
|
36
|
+
default_params =
|
37
|
+
multiple: true
|
38
|
+
width: '100%'
|
39
|
+
initSelection: (element, callback) ->
|
40
|
+
$(element).val('')
|
41
|
+
callback $(element).data('init')
|
42
|
+
ajax:
|
43
|
+
url: '/select2/results'
|
44
|
+
dataType: 'json'
|
45
|
+
data: (term, page) ->
|
46
|
+
term: term
|
47
|
+
page: page
|
48
|
+
model: $(this).data('model')
|
49
|
+
column: $(this).data('column')
|
50
|
+
results: (data, page) ->
|
51
|
+
data
|
52
|
+
this.select2 $.extend(true, default_params, params)
|
53
|
+
$('.select2').select2
|
54
|
+
width: '100%'
|
55
|
+
$('.select2-single').select2_single()
|
56
|
+
$('.select2-multiple').select2_multiple()
|
57
|
+
$('.select2-tags-array').select2
|
58
|
+
tags: []
|
59
|
+
width: '100%'
|
60
|
+
initSelection: (element, callback) ->
|
61
|
+
$(element).val('')
|
62
|
+
callback $(element).data('init').map (value) ->
|
63
|
+
id: value, text: value
|
64
|
+
createSearchChoice: (term) ->
|
65
|
+
id: term, text: term
|
66
|
+
$('.select2-tags').select2
|
67
|
+
multiple: true
|
68
|
+
width: '100%'
|
69
|
+
initSelection: (element, callback) ->
|
70
|
+
callback $.map(element.val().split(','), (value) -> id: $.trim(value), text: $.trim(value))
|
71
|
+
createSearchChoice: (term) ->
|
72
|
+
id: term, text: term
|
73
|
+
ajax:
|
74
|
+
url: '/select2/tags'
|
75
|
+
dataType: 'json'
|
76
|
+
data: (term, page) ->
|
77
|
+
term: term
|
78
|
+
page: page
|
79
|
+
context: $(this).data('context')
|
80
|
+
results: (data, page) -> data
|
81
|
+
$('.select2-polymorphic').change (e) ->
|
82
|
+
model_name = $(this).val()
|
83
|
+
column_name = $(this).data('models')[model_name]
|
84
|
+
target = $(this).data('target') || '#' + this.id.replace('_type', '_id')
|
85
|
+
$(target).select2
|
86
|
+
width: '100%'
|
87
|
+
initSelection: (element, callback) ->
|
88
|
+
callback
|
89
|
+
id: element.val()
|
90
|
+
text: element.data('text')
|
91
|
+
ajax:
|
92
|
+
url: '/select2/results'
|
93
|
+
dataType: 'json'
|
94
|
+
data: (term, page) ->
|
95
|
+
term: term
|
96
|
+
page: page
|
97
|
+
model: model_name
|
98
|
+
column: column_name
|
99
|
+
results: (data, page) -> data
|
100
|
+
$('.select2-polymorphic').trigger('change')
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Select2Controller < ApplicationController
|
2
|
+
include Select2Helper::Errors
|
3
|
+
|
4
|
+
def tags
|
5
|
+
@tags = ActsAsTaggableOn::Tag.page(params[:page]).order(:name)
|
6
|
+
@tags = @tags.where('name ILIKE ?', "%#{params[:term]}%") if params[:term].present?
|
7
|
+
@tags = @tags.includes(:taggings).where('taggings.context' => params[:context]) if params[:context].present?
|
8
|
+
end
|
9
|
+
|
10
|
+
def results
|
11
|
+
model = params[:model].constantize
|
12
|
+
raise InvalidModel unless model < Select2Concern
|
13
|
+
raise NotInWhiteList unless model.select2_allowed_search? params[:column].to_sym
|
14
|
+
@records = model.page(params[:page])
|
15
|
+
@records = @records.where(params[:where]) if params[:where]
|
16
|
+
@records = @records.where("#{params[:column]} ILIKE ?", "%#{params[:term]}%") if params[:term].present?
|
17
|
+
end
|
18
|
+
|
19
|
+
def polymorphic
|
20
|
+
model_class = params[:model].constantize
|
21
|
+
@records = model_class.page(params[:page])
|
22
|
+
@records = @records.where("#{params[:column]} ILIKE ?", "%#{params[:term]}%") if params[:term].present?
|
23
|
+
render :results
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Select2Concern
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
after_initialize do
|
5
|
+
self.class.instance_methods.grep(/ids=$/) do |method_name|
|
6
|
+
self.class.send(:define_method, method_name) do |value|
|
7
|
+
value = value.split(',') if value.is_a? String
|
8
|
+
super value
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
include Select2Helper::Errors
|
16
|
+
|
17
|
+
def select2_white_list *names
|
18
|
+
@select2_white_list = names
|
19
|
+
end
|
20
|
+
|
21
|
+
def select2_allowed_search? column_name
|
22
|
+
raise InvalidColumnName unless attribute_method? column_name
|
23
|
+
@select2_white_list.include? column_name
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//= require jquery
|
13
|
+
//= require select2
|
14
|
+
//= require select2_helper
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
12
|
+
*
|
13
|
+
*= require select2
|
14
|
+
*= require_tree .
|
15
|
+
*= require_self
|
16
|
+
*/
|
@@ -0,0 +1,56 @@
|
|
1
|
+
body { background-color: #fff; color: #333; }
|
2
|
+
|
3
|
+
body, p, ol, ul, td {
|
4
|
+
font-family: verdana, arial, helvetica, sans-serif;
|
5
|
+
font-size: 13px;
|
6
|
+
line-height: 18px;
|
7
|
+
}
|
8
|
+
|
9
|
+
pre {
|
10
|
+
background-color: #eee;
|
11
|
+
padding: 10px;
|
12
|
+
font-size: 11px;
|
13
|
+
}
|
14
|
+
|
15
|
+
a { color: #000; }
|
16
|
+
a:visited { color: #666; }
|
17
|
+
a:hover { color: #fff; background-color:#000; }
|
18
|
+
|
19
|
+
div.field, div.actions {
|
20
|
+
margin-bottom: 10px;
|
21
|
+
}
|
22
|
+
|
23
|
+
#notice {
|
24
|
+
color: green;
|
25
|
+
}
|
26
|
+
|
27
|
+
.field_with_errors {
|
28
|
+
padding: 2px;
|
29
|
+
background-color: red;
|
30
|
+
display: table;
|
31
|
+
}
|
32
|
+
|
33
|
+
#error_explanation {
|
34
|
+
width: 450px;
|
35
|
+
border: 2px solid red;
|
36
|
+
padding: 7px;
|
37
|
+
padding-bottom: 0;
|
38
|
+
margin-bottom: 20px;
|
39
|
+
background-color: #f0f0f0;
|
40
|
+
}
|
41
|
+
|
42
|
+
#error_explanation h2 {
|
43
|
+
text-align: left;
|
44
|
+
font-weight: bold;
|
45
|
+
padding: 5px 5px 5px 15px;
|
46
|
+
font-size: 12px;
|
47
|
+
margin: -7px;
|
48
|
+
margin-bottom: 0px;
|
49
|
+
background-color: #c00;
|
50
|
+
color: #fff;
|
51
|
+
}
|
52
|
+
|
53
|
+
#error_explanation ul li {
|
54
|
+
font-size: 12px;
|
55
|
+
list-style: square;
|
56
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class ProjectsController < ApplicationController
|
2
|
+
before_action :set_project, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /projects
|
5
|
+
def index
|
6
|
+
@projects = Project.all
|
7
|
+
end
|
8
|
+
|
9
|
+
# GET /projects/1
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /projects/new
|
14
|
+
def new
|
15
|
+
@project = Project.new
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /projects/1/edit
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
# POST /projects
|
23
|
+
def create
|
24
|
+
@project = Project.new(project_params)
|
25
|
+
|
26
|
+
if @project.save
|
27
|
+
redirect_to @project, notice: 'Project was successfully created.'
|
28
|
+
else
|
29
|
+
render :new
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# PATCH/PUT /projects/1
|
34
|
+
def update
|
35
|
+
if @project.update(project_params)
|
36
|
+
redirect_to @project, notice: 'Project was successfully updated.'
|
37
|
+
else
|
38
|
+
render :edit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# DELETE /projects/1
|
43
|
+
def destroy
|
44
|
+
@project.destroy
|
45
|
+
redirect_to projects_url, notice: 'Project was successfully destroyed.'
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
# Use callbacks to share common setup or constraints between actions.
|
50
|
+
def set_project
|
51
|
+
@project = Project.find(params[:id])
|
52
|
+
end
|
53
|
+
|
54
|
+
# Only allow a trusted parameter "white list" through.
|
55
|
+
def project_params
|
56
|
+
params.require(:project).permit(:name, :content, :task_ids)
|
57
|
+
end
|
58
|
+
end
|