select2_helper 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +32 -0
  4. data/app/assets/javascripts/select2_helper.js.coffee +100 -0
  5. data/app/controllers/select2_controller.rb +25 -0
  6. data/app/models/concerns/select2_concern.rb +26 -0
  7. data/app/views/select2/results.json.jbuilder +5 -0
  8. data/app/views/select2/tags.json.jbuilder +5 -0
  9. data/config/routes.rb +4 -0
  10. data/lib/select2_helper.rb +9 -0
  11. data/lib/select2_helper/errors.rb +7 -0
  12. data/lib/select2_helper/version.rb +3 -0
  13. data/lib/tasks/select2_helper_tasks.rake +4 -0
  14. data/test/dummy/README.rdoc +28 -0
  15. data/test/dummy/Rakefile +6 -0
  16. data/test/dummy/app/assets/javascripts/application.js +15 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +16 -0
  18. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  19. data/test/dummy/app/controllers/application_controller.rb +5 -0
  20. data/test/dummy/app/controllers/pages_controller.rb +4 -0
  21. data/test/dummy/app/controllers/projects_controller.rb +58 -0
  22. data/test/dummy/app/controllers/tasks_controller.rb +58 -0
  23. data/test/dummy/app/helpers/application_helper.rb +2 -0
  24. data/test/dummy/app/models/project.rb +5 -0
  25. data/test/dummy/app/models/task.rb +5 -0
  26. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  27. data/test/dummy/app/views/pages/index.html.erb +37 -0
  28. data/test/dummy/app/views/projects/_form.html.erb +31 -0
  29. data/test/dummy/app/views/projects/edit.html.erb +6 -0
  30. data/test/dummy/app/views/projects/index.html.erb +27 -0
  31. data/test/dummy/app/views/projects/new.html.erb +5 -0
  32. data/test/dummy/app/views/projects/show.html.erb +14 -0
  33. data/test/dummy/app/views/tasks/_form.html.erb +29 -0
  34. data/test/dummy/app/views/tasks/edit.html.erb +6 -0
  35. data/test/dummy/app/views/tasks/index.html.erb +29 -0
  36. data/test/dummy/app/views/tasks/new.html.erb +5 -0
  37. data/test/dummy/app/views/tasks/show.html.erb +19 -0
  38. data/test/dummy/bin/bundle +3 -0
  39. data/test/dummy/bin/rails +4 -0
  40. data/test/dummy/bin/rake +4 -0
  41. data/test/dummy/config.ru +4 -0
  42. data/test/dummy/config/application.rb +26 -0
  43. data/test/dummy/config/boot.rb +5 -0
  44. data/test/dummy/config/database.yml +85 -0
  45. data/test/dummy/config/environment.rb +5 -0
  46. data/test/dummy/config/environments/development.rb +37 -0
  47. data/test/dummy/config/environments/production.rb +83 -0
  48. data/test/dummy/config/environments/test.rb +39 -0
  49. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  51. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  52. data/test/dummy/config/initializers/inflections.rb +16 -0
  53. data/test/dummy/config/initializers/mime_types.rb +4 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/dummy/config/locales/en.yml +23 -0
  57. data/test/dummy/config/routes.rb +59 -0
  58. data/test/dummy/config/secrets.yml +22 -0
  59. data/test/dummy/db/migrate/20140527180322_create_projects.rb +10 -0
  60. data/test/dummy/db/migrate/20140527180427_create_tasks.rb +11 -0
  61. data/test/dummy/db/schema.rb +36 -0
  62. data/test/dummy/log/development.log +9895 -0
  63. data/test/dummy/public/404.html +67 -0
  64. data/test/dummy/public/422.html +67 -0
  65. data/test/dummy/public/500.html +66 -0
  66. data/test/dummy/public/favicon.ico +0 -0
  67. data/test/dummy/test/controllers/pages_controller_test.rb +9 -0
  68. data/test/dummy/test/controllers/projects_controller_test.rb +49 -0
  69. data/test/dummy/test/controllers/tasks_controller_test.rb +49 -0
  70. data/test/dummy/test/factories/projects.rb +8 -0
  71. data/test/dummy/test/factories/tasks.rb +9 -0
  72. data/test/dummy/test/fixtures/projects.yml +9 -0
  73. data/test/dummy/test/fixtures/tasks.yml +11 -0
  74. data/test/dummy/test/models/project_test.rb +7 -0
  75. data/test/dummy/test/models/task_test.rb +7 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/142e7fd2c85a87d270e4fd271e945642 +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/20a2742a642444d35da6761f661b3fe0 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/25819886b1b5d849b15d78a77bfae37d +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/35fbb4453edc7ae6ac6704f1002f32df +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/44d54dc4f4f5f01ad21b0c3b86be2913 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/47519dd4ec1de6cedccedec8561ab352 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/501a695a5f241c549cac4109a7f21e35 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/574b5665e77ea1b5e37666852db46012 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/59dbe4fb498319628373091eae217b85 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/6670943499444e8b67b53f147c9691c8 +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/73214d449277f121ae99674373349b9c +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/74f0b8d7fd1d954cef0b5a6a1d46d4e6 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/86ea3c481cf2fa8c2cbc7736a6d2f578 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/8e83573f6393d13316efb7d02d1ce2f0 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/93ec664048bf1c019655ba77098c83c5 +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/9dec80587c00d47a7ef1f8dd7bb35198 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/b45b717a170260b00060c40280c4ed41 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/c4d0bdedab06899031ceb8170acbfda4 +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/d5ff021bac42e2a975828c6d5c347278 +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/ded9139cab353ae56b68a46be15a9ced +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/f5a52a7d62f9c8b29b911bab47331da7 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  106. data/test/select2_helper_test.rb +7 -0
  107. data/test/test_helper.rb +15 -0
  108. metadata +315 -0
@@ -0,0 +1,58 @@
1
+ class TasksController < ApplicationController
2
+ before_action :set_task, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /tasks
5
+ def index
6
+ @tasks = Task.all
7
+ end
8
+
9
+ # GET /tasks/1
10
+ def show
11
+ end
12
+
13
+ # GET /tasks/new
14
+ def new
15
+ @task = Task.new
16
+ end
17
+
18
+ # GET /tasks/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /tasks
23
+ def create
24
+ @task = Task.new(task_params)
25
+
26
+ if @task.save
27
+ redirect_to @task, notice: 'Task was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /tasks/1
34
+ def update
35
+ if @task.update(task_params)
36
+ redirect_to @task, notice: 'Task was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /tasks/1
43
+ def destroy
44
+ @task.destroy
45
+ redirect_to tasks_url, notice: 'Task was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_task
51
+ @task = Task.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def task_params
56
+ params.require(:task).permit(:project_id, :description, :status)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,5 @@
1
+ class Project < ActiveRecord::Base
2
+ include Select2Concern
3
+ select2_white_list :name
4
+ has_many :tasks
5
+ end
@@ -0,0 +1,5 @@
1
+ class Task < ActiveRecord::Base
2
+ include Select2Concern
3
+ select2_white_list :status
4
+ belongs_to :project
5
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,37 @@
1
+ <form action="">
2
+ <h1>Single Select</h1>
3
+ <%= text_field_tag :single_demo, nil,
4
+ class: 'select2-single',
5
+ data: {
6
+ model: :Project,
7
+ column: :name
8
+ }
9
+ %>
10
+
11
+ <h1>Multiple Select</h1>
12
+ <%= text_field_tag :multiple_demo, nil,
13
+ class: 'select2-multiple',
14
+ data: {
15
+ model: :Project,
16
+ column: :name
17
+ }
18
+ %>
19
+
20
+ <h1>Nested Select</h1>
21
+ <%= text_field_tag :level_1, nil,
22
+ class: 'select2-single',
23
+ data: {
24
+ model: :Project,
25
+ column: :name,
26
+ child_field: '#level_2'
27
+ }
28
+ %>
29
+
30
+ <%= text_field_tag :level_2, nil,
31
+ data: {
32
+ model: :Task,
33
+ column: :status,
34
+ foreign_key: :project_id
35
+ }
36
+ %>
37
+ </form>
@@ -0,0 +1,31 @@
1
+ <%= form_for(@project) do |f| %>
2
+ <% if @project.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@project.errors.count, "error") %> prohibited this project from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @project.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :name %><br>
16
+ <%= f.text_field :name %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :content %><br>
20
+ <%= f.text_area :content %>
21
+ </div>
22
+
23
+ <div class="field">
24
+ <%= f.label :task_ids %><br>
25
+ <%= f.text_field :task_ids, class: 'select2-multiple', data: {model: :Task, column: :status, init: f.object.tasks.map{|task| {id: task.id, text: task.status } } } %>
26
+ </div>
27
+
28
+ <div class="actions">
29
+ <%= f.submit %>
30
+ </div>
31
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing project</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @project %> |
6
+ <%= link_to 'Back', projects_path %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing projects</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Name</th>
7
+ <th>Content</th>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @projects.each do |project| %>
14
+ <tr>
15
+ <td><%= project.name %></td>
16
+ <td><%= project.content %></td>
17
+ <td><%= link_to 'Show', project %></td>
18
+ <td><%= link_to 'Edit', edit_project_path(project) %></td>
19
+ <td><%= link_to 'Destroy', project, method: :delete, data: { confirm: 'Are you sure?' } %></td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ </table>
24
+
25
+ <br>
26
+
27
+ <%= link_to 'New Project', new_project_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New project</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', projects_path %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Name:</strong>
5
+ <%= @project.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Content:</strong>
10
+ <%= @project.content %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_project_path(@project) %> |
14
+ <%= link_to 'Back', projects_path %>
@@ -0,0 +1,29 @@
1
+ <%= form_for(@task) do |f| %>
2
+ <% if @task.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@task.errors.count, "error") %> prohibited this task from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @task.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :project_id %><br>
16
+ <%= f.text_field :project_id, class: 'select2-single', data: {model: :Project, column: :name, init: f.object.project.try(:name)} %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :description %><br>
20
+ <%= f.text_area :description %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :status %><br>
24
+ <%= f.text_field :status %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing task</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @task %> |
6
+ <%= link_to 'Back', tasks_path %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing tasks</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Project</th>
7
+ <th>Description</th>
8
+ <th>Status</th>
9
+ <th colspan="3"></th>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% @tasks.each do |task| %>
15
+ <tr>
16
+ <td><%= task.project %></td>
17
+ <td><%= task.description %></td>
18
+ <td><%= task.status %></td>
19
+ <td><%= link_to 'Show', task %></td>
20
+ <td><%= link_to 'Edit', edit_task_path(task) %></td>
21
+ <td><%= link_to 'Destroy', task, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Task', new_task_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New task</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', tasks_path %>
@@ -0,0 +1,19 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Project:</strong>
5
+ <%= @task.project %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Description:</strong>
10
+ <%= @task.description %>
11
+ </p>
12
+
13
+ <p>
14
+ <strong>Status:</strong>
15
+ <%= @task.status %>
16
+ </p>
17
+
18
+ <%= link_to 'Edit', edit_task_path(@task) %> |
19
+ <%= link_to 'Back', tasks_path %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "select2_helper"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+ config.generators.assets = false
22
+ config.generators.helper = false
23
+ config.generators.jbuilder = false
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,85 @@
1
+ # PostgreSQL. Versions 8.2 and up are supported.
2
+ #
3
+ # Install the pg driver:
4
+ # gem install pg
5
+ # On OS X with Homebrew:
6
+ # gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7
+ # On OS X with MacPorts:
8
+ # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
9
+ # On Windows:
10
+ # gem install pg
11
+ # Choose the win32 build.
12
+ # Install PostgreSQL and put its /bin directory on your path.
13
+ #
14
+ # Configure Using Gemfile
15
+ # gem 'pg'
16
+ #
17
+ default: &default
18
+ adapter: postgresql
19
+ encoding: unicode
20
+ # For details on connection pooling, see rails configuration guide
21
+ # http://guides.rubyonrails.org/configuring.html#database-pooling
22
+ pool: 5
23
+
24
+ development:
25
+ <<: *default
26
+ database: dummy_development
27
+
28
+ # The specified database role being used to connect to postgres.
29
+ # To create additional roles in postgres see `$ createuser --help`.
30
+ # When left blank, postgres will use the default role. This is
31
+ # the same name as the operating system user that initialized the database.
32
+ #username: dummy
33
+
34
+ # The password associated with the postgres role (username).
35
+ #password:
36
+
37
+ # Connect on a TCP socket. Omitted by default since the client uses a
38
+ # domain socket that doesn't need configuration. Windows does not have
39
+ # domain sockets, so uncomment these lines.
40
+ #host: localhost
41
+
42
+ # The TCP port the server listens on. Defaults to 5432.
43
+ # If your server runs on a different port number, change accordingly.
44
+ #port: 5432
45
+
46
+ # Schema search path. The server defaults to $user,public
47
+ #schema_search_path: myapp,sharedapp,public
48
+
49
+ # Minimum log levels, in increasing order:
50
+ # debug5, debug4, debug3, debug2, debug1,
51
+ # log, notice, warning, error, fatal, and panic
52
+ # Defaults to warning.
53
+ #min_messages: notice
54
+
55
+ # Warning: The database defined as "test" will be erased and
56
+ # re-generated from your development database when you run "rake".
57
+ # Do not set this db to the same as development or production.
58
+ test:
59
+ <<: *default
60
+ database: dummy_test
61
+
62
+ # As with config/secrets.yml, you never want to store sensitive information,
63
+ # like your database password, in your source code. If your source code is
64
+ # ever seen by anyone, they now have access to your database.
65
+ #
66
+ # Instead, provide the password as a unix environment variable when you boot
67
+ # the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
68
+ # for a full rundown on how to provide these environment variables in a
69
+ # production deployment.
70
+ #
71
+ # On Heroku and other platform providers, you may have a full connection URL
72
+ # available as an environment variable. For example:
73
+ #
74
+ # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
75
+ #
76
+ # You can use this database configuration with:
77
+ #
78
+ # production:
79
+ # url: <%= ENV['DATABASE_URL'] %>
80
+ #
81
+ production:
82
+ <<: *default
83
+ database: dummy_production
84
+ username: dummy
85
+ password: <%= ENV['DUMMY_DATABASE_PASSWORD'] %>