dynamic_controller 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +4 -0
  3. data/README.md +43 -0
  4. data/Rakefile +1 -0
  5. data/dynamic_controller.gemspec +26 -0
  6. data/lib/dynamic_controller.rb +180 -0
  7. data/lib/dynamic_controller/version.rb +3 -0
  8. data/spec/controllers/crud_actions_html_spec.rb +112 -0
  9. data/spec/controllers/crud_actions_json_spec.rb +92 -0
  10. data/spec/controllers/nested_crud_actions_html_spec.rb +125 -0
  11. data/spec/controllers/nested_crud_actions_json_spec.rb +98 -0
  12. data/spec/dummy/.gitignore +15 -0
  13. data/spec/dummy/Gemfile +13 -0
  14. data/spec/dummy/README.rdoc +261 -0
  15. data/spec/dummy/Rakefile +7 -0
  16. data/spec/dummy/app/assets/images/rails.png +0 -0
  17. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  18. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  19. data/spec/dummy/app/assets/stylesheets/scaffolds.css.scss +69 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/controllers/cities_controller.rb +94 -0
  22. data/spec/dummy/app/controllers/countries_controller.rb +86 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/mailers/.gitkeep +0 -0
  25. data/spec/dummy/app/models/.gitkeep +0 -0
  26. data/spec/dummy/app/models/city.rb +5 -0
  27. data/spec/dummy/app/models/country.rb +5 -0
  28. data/spec/dummy/app/views/cities/_form.html.erb +25 -0
  29. data/spec/dummy/app/views/cities/edit.html.erb +6 -0
  30. data/spec/dummy/app/views/cities/index.html.erb +25 -0
  31. data/spec/dummy/app/views/cities/new.html.erb +5 -0
  32. data/spec/dummy/app/views/cities/show.html.erb +15 -0
  33. data/spec/dummy/app/views/countries/_form.html.erb +21 -0
  34. data/spec/dummy/app/views/countries/edit.html.erb +6 -0
  35. data/spec/dummy/app/views/countries/index.html.erb +23 -0
  36. data/spec/dummy/app/views/countries/new.html.erb +5 -0
  37. data/spec/dummy/app/views/countries/show.html.erb +10 -0
  38. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  39. data/spec/dummy/config.ru +4 -0
  40. data/spec/dummy/config/application.rb +62 -0
  41. data/spec/dummy/config/boot.rb +6 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +5 -0
  44. data/spec/dummy/config/environments/development.rb +37 -0
  45. data/spec/dummy/config/environments/production.rb +67 -0
  46. data/spec/dummy/config/environments/test.rb +37 -0
  47. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/spec/dummy/config/initializers/inflections.rb +15 -0
  49. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  50. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  51. data/spec/dummy/config/initializers/session_store.rb +8 -0
  52. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  53. data/spec/dummy/config/locales/en.yml +5 -0
  54. data/spec/dummy/config/routes.rb +5 -0
  55. data/spec/dummy/db/migrate/20120907174827_create_countries.rb +9 -0
  56. data/spec/dummy/db/migrate/20120907230842_create_cities.rb +11 -0
  57. data/spec/dummy/db/schema.rb +31 -0
  58. data/spec/dummy/db/seeds.rb +7 -0
  59. data/spec/dummy/doc/README_FOR_APP +2 -0
  60. data/spec/dummy/lib/assets/.gitkeep +0 -0
  61. data/spec/dummy/lib/tasks/.gitkeep +0 -0
  62. data/spec/dummy/log/.gitkeep +0 -0
  63. data/spec/dummy/public/404.html +26 -0
  64. data/spec/dummy/public/422.html +26 -0
  65. data/spec/dummy/public/500.html +25 -0
  66. data/spec/dummy/public/favicon.ico +0 -0
  67. data/spec/dummy/public/index.html +241 -0
  68. data/spec/dummy/public/robots.txt +5 -0
  69. data/spec/dummy/script/rails +6 -0
  70. data/spec/dummy/vendor/assets/javascripts/.gitkeep +0 -0
  71. data/spec/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  72. data/spec/dummy/vendor/plugins/.gitkeep +0 -0
  73. data/spec/factories.rb +12 -0
  74. data/spec/spec_helper.rb +34 -0
  75. metadata +185 -0
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -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
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
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 top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,69 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ p, ol, ul, td {
10
+ font-family: verdana, arial, helvetica, sans-serif;
11
+ font-size: 13px;
12
+ line-height: 18px;
13
+ }
14
+
15
+ pre {
16
+ background-color: #eee;
17
+ padding: 10px;
18
+ font-size: 11px;
19
+ }
20
+
21
+ a {
22
+ color: #000;
23
+ &:visited {
24
+ color: #666;
25
+ }
26
+ &:hover {
27
+ color: #fff;
28
+ background-color: #000;
29
+ }
30
+ }
31
+
32
+ div {
33
+ &.field, &.actions {
34
+ margin-bottom: 10px;
35
+ }
36
+ }
37
+
38
+ #notice {
39
+ color: green;
40
+ }
41
+
42
+ .field_with_errors {
43
+ padding: 2px;
44
+ background-color: red;
45
+ display: table;
46
+ }
47
+
48
+ #error_explanation {
49
+ width: 450px;
50
+ border: 2px solid red;
51
+ padding: 7px;
52
+ padding-bottom: 0;
53
+ margin-bottom: 20px;
54
+ background-color: #f0f0f0;
55
+ h2 {
56
+ text-align: left;
57
+ font-weight: bold;
58
+ padding: 5px 5px 5px 15px;
59
+ font-size: 12px;
60
+ margin: -7px;
61
+ margin-bottom: 0px;
62
+ background-color: #c00;
63
+ color: #fff;
64
+ }
65
+ ul li {
66
+ font-size: 12px;
67
+ list-style: square;
68
+ }
69
+ }
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,94 @@
1
+ class CitiesController < ApplicationController
2
+ has_crud_actions nested_of: Country
3
+ =begin
4
+ before_filter :load_country
5
+
6
+ # GET /cities
7
+ # GET /cities.json
8
+ def index
9
+ @cities = City.all
10
+
11
+ respond_to do |format|
12
+ format.html # index.html.erb
13
+ format.json { render json: @cities }
14
+ end
15
+ end
16
+
17
+ # GET /cities/1
18
+ # GET /cities/1.json
19
+ def show
20
+ @city = City.find(params[:id])
21
+
22
+ respond_to do |format|
23
+ format.html # show.html.erb
24
+ format.json { render json: @city }
25
+ end
26
+ end
27
+
28
+ # GET /cities/new
29
+ # GET /cities/new.json
30
+ def new
31
+ @city = City.new
32
+
33
+ respond_to do |format|
34
+ format.html # new.html.erb
35
+ format.json { render json: @city }
36
+ end
37
+ end
38
+
39
+ # GET /cities/1/edit
40
+ def edit
41
+ @city = City.find(params[:id])
42
+ end
43
+
44
+ # POST /cities
45
+ # POST /cities.json
46
+ def create
47
+ @city = City.new(params[:city])
48
+
49
+ respond_to do |format|
50
+ if @city.save
51
+ format.html { redirect_to [@country, @city], notice: 'City was successfully created.' }
52
+ format.json { render json: @city, status: :created }
53
+ else
54
+ format.html { render action: "new" }
55
+ format.json { render json: @city.errors, status: :unprocessable_entity }
56
+ end
57
+ end
58
+ end
59
+
60
+ # PUT /cities/1
61
+ # PUT /cities/1.json
62
+ def update
63
+ @city = City.find(params[:id])
64
+
65
+ respond_to do |format|
66
+ if @city.update_attributes(params[:city])
67
+ format.html { redirect_to [@country, @city], notice: 'City was successfully updated.' }
68
+ format.json { head :no_content }
69
+ else
70
+ format.html { render action: "edit" }
71
+ format.json { render json: @city.errors, status: :unprocessable_entity }
72
+ end
73
+ end
74
+ end
75
+
76
+ # DELETE /cities/1
77
+ # DELETE /cities/1.json
78
+ def destroy
79
+ @city = City.find(params[:id])
80
+ @city.destroy
81
+
82
+ respond_to do |format|
83
+ format.html { redirect_to country_cities_url(@country) }
84
+ format.json { head :no_content }
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def load_country
91
+ @country = Country.find(params[:country_id])
92
+ end
93
+ =end
94
+ end
@@ -0,0 +1,86 @@
1
+ class CountriesController < ApplicationController
2
+ has_crud_actions
3
+ =begin
4
+ # GET /countries
5
+ # GET /countries.json
6
+ def index
7
+ @countries = Country.all
8
+
9
+ respond_to do |format|
10
+ format.html # index.html.erb
11
+ format.json { render json: @countries }
12
+ end
13
+ end
14
+
15
+ # GET /countries/1
16
+ # GET /countries/1.json
17
+ def show
18
+ @country = Country.find(params[:id])
19
+
20
+ respond_to do |format|
21
+ format.html # show.html.erb
22
+ format.json { render json: @country }
23
+ end
24
+ end
25
+
26
+ # GET /countries/new
27
+ # GET /countries/new.json
28
+ def new
29
+ @country = Country.new
30
+
31
+ respond_to do |format|
32
+ format.html # new.html.erb
33
+ format.json { render json: @country }
34
+ end
35
+ end
36
+
37
+ # GET /countries/1/edit
38
+ def edit
39
+ @country = Country.find(params[:id])
40
+ end
41
+
42
+ # POST /countries
43
+ # POST /countries.json
44
+ def create
45
+ @country = Country.new(params[:country])
46
+
47
+ respond_to do |format|
48
+ if @country.save
49
+ format.html { redirect_to @country, notice: 'Country was successfully created.' }
50
+ format.json { render json: @country, status: :created, location: @country }
51
+ else
52
+ format.html { render action: "new" }
53
+ format.json { render json: @country.errors, status: :unprocessable_entity }
54
+ end
55
+ end
56
+ end
57
+
58
+ # PUT /countries/1
59
+ # PUT /countries/1.json
60
+ def update
61
+ @country = Country.find(params[:id])
62
+
63
+ respond_to do |format|
64
+ if @country.update_attributes(params[:country])
65
+ format.html { redirect_to @country, notice: 'Country was successfully updated.' }
66
+ format.json { head :no_content }
67
+ else
68
+ format.html { render action: "edit" }
69
+ format.json { render json: @country.errors, status: :unprocessable_entity }
70
+ end
71
+ end
72
+ end
73
+
74
+ # DELETE /countries/1
75
+ # DELETE /countries/1.json
76
+ def destroy
77
+ @country = Country.find(params[:id])
78
+ @country.destroy
79
+
80
+ respond_to do |format|
81
+ format.html { redirect_to countries_url }
82
+ format.json { head :no_content }
83
+ end
84
+ end
85
+ =end
86
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ class City < ActiveRecord::Base
2
+ belongs_to :country
3
+ attr_accessible :country_id, :name
4
+ validates_presence_of :country_id, :name
5
+ end
@@ -0,0 +1,5 @@
1
+ class Country < ActiveRecord::Base
2
+ has_many :cities, dependent: :destroy
3
+ attr_accessible :name
4
+ validates_presence_of :name
5
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for([@country, @city]) do |f| %>
2
+ <% if @city.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@city.errors.count, "error") %> prohibited this city from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @city.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></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 :country %><br />
20
+ <%= f.select :country_id, Country.scoped.map{|c| [c.name, c.id]}, prompt: '[Select]' %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing city</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', [@country, @city] %> |
6
+ <%= link_to 'Back', country_cities_path(@country) %>
@@ -0,0 +1,25 @@
1
+ <h1>Listing cities</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th>Country</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @cities.each do |city| %>
13
+ <tr>
14
+ <td><%= city.name %></td>
15
+ <td><%= city.country.name %></td>
16
+ <td><%= link_to 'Show', [@country, city] %></td>
17
+ <td><%= link_to 'Edit', edit_country_city_path(@country, city) %></td>
18
+ <td><%= link_to 'Destroy', [@country, city], method: :delete, data: { confirm: 'Are you sure?' } %></td>
19
+ </tr>
20
+ <% end %>
21
+ </table>
22
+
23
+ <br />
24
+
25
+ <%= link_to 'New City', new_country_city_path(@country) %>
@@ -0,0 +1,5 @@
1
+ <h1>New city</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', country_cities_path(@country) %>
@@ -0,0 +1,15 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Name:</b>
5
+ <%= @city.name %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Country:</b>
10
+ <%= @city.country.name %>
11
+ </p>
12
+
13
+
14
+ <%= link_to 'Edit', edit_country_city_path(@country, @city) %> |
15
+ <%= link_to 'Back', country_cities_path(@country) %>
@@ -0,0 +1,21 @@
1
+ <%= form_for(@country) do |f| %>
2
+ <% if @country.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@country.errors.count, "error") %> prohibited this country from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @country.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></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="actions">
19
+ <%= f.submit %>
20
+ </div>
21
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing country</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @country %> |
6
+ <%= link_to 'Back', countries_path %>
@@ -0,0 +1,23 @@
1
+ <h1>Listing countries</h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <th>Name</th>
6
+ <th></th>
7
+ <th></th>
8
+ <th></th>
9
+ </tr>
10
+
11
+ <% @countries.each do |country| %>
12
+ <tr>
13
+ <td><%= country.name %></td>
14
+ <td><%= link_to 'Show', country %></td>
15
+ <td><%= link_to 'Edit', edit_country_path(country) %></td>
16
+ <td><%= link_to 'Destroy', country, method: :delete, data: { confirm: 'Are you sure?' } %></td>
17
+ </tr>
18
+ <% end %>
19
+ </table>
20
+
21
+ <br />
22
+
23
+ <%= link_to 'New Country', new_country_path %>