sandboxy 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/pull_request_template.md +2 -2
- data/CHANGELOG.md +6 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/DEPRECATIONS.md +3 -1
- data/Gemfile +1 -1
- data/INSTALL.md +1 -1
- data/LICENSE +1 -1
- data/README.md +68 -38
- data/Rakefile +0 -1
- data/examples/rails_example/Gemfile +1 -0
- data/examples/rails_example/app/api/books/api.rb +33 -0
- data/examples/rails_example/app/assets/javascripts/{bars.coffee → applications.coffee} +0 -0
- data/examples/rails_example/app/assets/javascripts/{foos.coffee → authors.coffee} +0 -0
- data/examples/rails_example/app/assets/javascripts/books.coffee +3 -0
- data/examples/rails_example/app/assets/javascripts/libraries.coffee +3 -0
- data/examples/rails_example/app/assets/javascripts/sandbox.coffee +3 -0
- data/examples/rails_example/app/assets/stylesheets/applications.scss +3 -0
- data/examples/rails_example/app/assets/stylesheets/{foos.scss → authors.scss} +1 -1
- data/examples/rails_example/app/assets/stylesheets/{bars.scss → books.scss} +1 -1
- data/examples/rails_example/app/assets/stylesheets/libraries.scss +3 -0
- data/examples/rails_example/app/assets/stylesheets/sandbox.scss +3 -0
- data/examples/rails_example/app/controllers/application_controller.rb +5 -1
- data/examples/rails_example/app/controllers/applications_controller.rb +74 -0
- data/examples/rails_example/app/controllers/authors_controller.rb +77 -0
- data/examples/rails_example/app/controllers/books_controller.rb +77 -0
- data/examples/rails_example/app/controllers/libraries_controller.rb +77 -0
- data/examples/rails_example/app/controllers/sandbox_controller.rb +6 -0
- data/examples/rails_example/app/helpers/applications_helper.rb +2 -0
- data/examples/rails_example/app/helpers/authors_helper.rb +2 -0
- data/examples/rails_example/app/helpers/books_helper.rb +2 -0
- data/examples/rails_example/app/helpers/libraries_helper.rb +2 -0
- data/examples/rails_example/app/helpers/sandbox_helper.rb +2 -0
- data/examples/rails_example/app/models/application.rb +14 -0
- data/examples/rails_example/app/models/author.rb +2 -0
- data/examples/rails_example/app/models/book.rb +2 -0
- data/examples/rails_example/app/models/library.rb +2 -0
- data/examples/rails_example/app/views/applications/_application.json.jbuilder +2 -0
- data/examples/rails_example/app/views/applications/_form.html.erb +19 -0
- data/examples/rails_example/app/views/applications/edit.html.erb +6 -0
- data/examples/rails_example/app/views/applications/index.html.erb +25 -0
- data/examples/rails_example/app/views/applications/index.json.jbuilder +1 -0
- data/examples/rails_example/app/views/applications/new.html.erb +5 -0
- data/examples/rails_example/app/views/applications/show.html.erb +7 -0
- data/examples/rails_example/app/views/applications/show.json.jbuilder +1 -0
- data/examples/rails_example/app/views/authors/_author.json.jbuilder +2 -0
- data/examples/rails_example/app/views/authors/_form.html.erb +19 -0
- data/examples/rails_example/app/views/authors/edit.html.erb +6 -0
- data/examples/rails_example/app/views/authors/index.html.erb +25 -0
- data/examples/rails_example/app/views/authors/index.json.jbuilder +1 -0
- data/examples/rails_example/app/views/authors/new.html.erb +5 -0
- data/examples/rails_example/app/views/authors/show.html.erb +4 -0
- data/examples/rails_example/app/views/authors/show.json.jbuilder +1 -0
- data/examples/rails_example/app/views/books/_book.json.jbuilder +2 -0
- data/examples/rails_example/app/views/books/_form.html.erb +19 -0
- data/examples/rails_example/app/views/books/edit.html.erb +6 -0
- data/examples/rails_example/app/views/books/index.html.erb +25 -0
- data/examples/rails_example/app/views/books/index.json.jbuilder +1 -0
- data/examples/rails_example/app/views/books/new.html.erb +5 -0
- data/examples/rails_example/app/views/books/show.html.erb +4 -0
- data/examples/rails_example/app/views/books/show.json.jbuilder +1 -0
- data/examples/rails_example/app/views/libraries/_form.html.erb +19 -0
- data/examples/rails_example/app/views/libraries/_library.json.jbuilder +2 -0
- data/examples/rails_example/app/views/libraries/edit.html.erb +6 -0
- data/examples/rails_example/app/views/libraries/index.html.erb +25 -0
- data/examples/rails_example/app/views/libraries/index.json.jbuilder +1 -0
- data/examples/rails_example/app/views/libraries/new.html.erb +5 -0
- data/examples/rails_example/app/views/libraries/show.html.erb +4 -0
- data/examples/rails_example/app/views/libraries/show.json.jbuilder +1 -0
- data/examples/rails_example/config/initializers/grape.rb +2 -0
- data/examples/rails_example/config/initializers/sandboxy.rb +13 -0
- data/examples/rails_example/config/routes.rb +9 -3
- data/examples/rails_example/config/secrets.yml +2 -2
- data/examples/rails_example/db/migrate/20170827184048_create_books.rb +9 -0
- data/examples/rails_example/db/migrate/20170827184054_create_authors.rb +9 -0
- data/examples/rails_example/db/migrate/20170827184106_create_libraries.rb +9 -0
- data/examples/rails_example/db/migrate/20170827184304_create_applications.rb +11 -0
- data/examples/rails_example/db/migrate/{20170827105828_sandboxy_migration.rb → 20170827190815_sandboxy_migration.rb} +0 -0
- data/examples/rails_example/db/schema.rb +19 -3
- data/examples/rails_example/test/controllers/applications_controller_test.rb +48 -0
- data/examples/rails_example/test/controllers/authors_controller_test.rb +48 -0
- data/examples/rails_example/test/controllers/books_controller_test.rb +48 -0
- data/examples/rails_example/test/controllers/libraries_controller_test.rb +48 -0
- data/examples/rails_example/test/controllers/sandbox_controller_test.rb +7 -0
- data/examples/rails_example/test/fixtures/{bars.yml → applications.yml} +0 -0
- data/examples/rails_example/test/fixtures/{foos.yml → authors.yml} +0 -0
- data/examples/rails_example/test/fixtures/books.yml +11 -0
- data/examples/rails_example/test/fixtures/libraries.yml +11 -0
- data/examples/rails_example/test/models/application_test.rb +7 -0
- data/examples/rails_example/test/models/{bar_test.rb → author_test.rb} +1 -1
- data/examples/rails_example/test/models/{foo_test.rb → book_test.rb} +1 -1
- data/examples/rails_example/test/models/library_test.rb +7 -0
- data/examples/rails_example/test/system/applications_test.rb +9 -0
- data/examples/rails_example/test/system/authors_test.rb +9 -0
- data/examples/rails_example/test/system/books_test.rb +9 -0
- data/examples/rails_example/test/system/libraries_test.rb +9 -0
- data/lib/generators/sandboxy_generator.rb +4 -6
- data/lib/generators/templates/initializer.rb +13 -0
- data/lib/sandboxy/configuration.rb +11 -34
- data/lib/sandboxy/middleware.rb +3 -3
- data/lib/sandboxy/railtie.rb +3 -3
- data/lib/sandboxy/version.rb +1 -1
- data/lib/sandboxy.rb +12 -3
- data/sandboxy.gemspec +4 -6
- data/test/dummy30/config/initializers/sandboxy.rb +13 -0
- data/test/test_helper.rb +0 -2
- metadata +93 -78
- data/examples/rails_example/app/controllers/bars_controller.rb +0 -74
- data/examples/rails_example/app/controllers/foos_controller.rb +0 -74
- data/examples/rails_example/app/helpers/bars_helper.rb +0 -2
- data/examples/rails_example/app/helpers/foos_helper.rb +0 -2
- data/examples/rails_example/app/models/bar.rb +0 -2
- data/examples/rails_example/app/models/foo.rb +0 -2
- data/examples/rails_example/app/models/shared_sandbox.rb +0 -3
- data/examples/rails_example/app/views/bars/_bar.json.jbuilder +0 -2
- data/examples/rails_example/app/views/bars/_form.html.erb +0 -17
- data/examples/rails_example/app/views/bars/edit.html.erb +0 -6
- data/examples/rails_example/app/views/bars/index.html.erb +0 -25
- data/examples/rails_example/app/views/bars/index.json.jbuilder +0 -1
- data/examples/rails_example/app/views/bars/new.html.erb +0 -5
- data/examples/rails_example/app/views/bars/show.html.erb +0 -4
- data/examples/rails_example/app/views/bars/show.json.jbuilder +0 -1
- data/examples/rails_example/app/views/foos/_foo.json.jbuilder +0 -2
- data/examples/rails_example/app/views/foos/_form.html.erb +0 -17
- data/examples/rails_example/app/views/foos/edit.html.erb +0 -6
- data/examples/rails_example/app/views/foos/index.html.erb +0 -25
- data/examples/rails_example/app/views/foos/index.json.jbuilder +0 -1
- data/examples/rails_example/app/views/foos/new.html.erb +0 -5
- data/examples/rails_example/app/views/foos/show.html.erb +0 -4
- data/examples/rails_example/app/views/foos/show.json.jbuilder +0 -1
- data/examples/rails_example/config/sandboxy.yml +0 -13
- data/examples/rails_example/db/migrate/20170826223227_create_foos.rb +0 -8
- data/examples/rails_example/db/migrate/20170826223243_create_bars.rb +0 -8
- data/examples/rails_example/test/controllers/bars_controller_test.rb +0 -48
- data/examples/rails_example/test/controllers/foos_controller_test.rb +0 -48
- data/examples/rails_example/test/system/bars_test.rb +0 -9
- data/examples/rails_example/test/system/foos_test.rb +0 -9
- data/lib/generators/templates/configuration.yml.erb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5eac48d43fcaf454f691ca0169d9ba357f31e46b30aa452e4de0d99f172e9a7
|
4
|
+
data.tar.gz: 61eeb91dfcd1b788cd95b4f8944684b792552e1f378b46c910eb46e8b2a454a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be725877526b7a6e616670c73a0ea5348a0feee76e05d600ad4aa404e04d64b5e1dce0dcb17a2aadadcd692235e3ac09a6f7ad942b51abe652ce17ec3890d1ec
|
7
|
+
data.tar.gz: 51d58e7689ffef821e4d44a71be4aea455b3e19976c58c963caa1c968789754f25f12eb4f4dcaffe0bd46cc00ba80fb043aca9665c88939bb4d7babae4333e5d
|
@@ -16,6 +16,6 @@ CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the f
|
|
16
16
|
|
17
17
|
Finally, if your pull request affects documentation or any non-code
|
18
18
|
changes, guidelines for those changes are [available
|
19
|
-
here](https://github.com/
|
19
|
+
here](https://github.com/jonhue/sandboxy/blob/master/CONTRIBUTING.md)
|
20
20
|
|
21
|
-
Thanks for contributing to
|
21
|
+
Thanks for contributing to Sandboxy!
|
data/CHANGELOG.md
CHANGED
data/CODE_OF_CONDUCT.md
CHANGED
@@ -34,7 +34,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe
|
|
34
34
|
|
35
35
|
## Enforcement
|
36
36
|
|
37
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jonas.huebotter@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
|
38
38
|
|
39
39
|
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
|
40
40
|
|
data/DEPRECATIONS.md
CHANGED
data/Gemfile
CHANGED
data/INSTALL.md
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# Sandboxy
|
1
|
+
# Sandboxy
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sandboxy.svg)](https://badge.fury.io/rb/sandboxy) <img src="https://travis-ci.org/jonhue/sandboxy.svg?branch=master" />
|
4
4
|
|
5
|
-
Sandboxy allows you to use virtual data-oriented environments inside a Rails application while being able to switch
|
5
|
+
Sandboxy allows you to use virtual data-oriented environments inside a Rails application while being able to switch between them at runtime. It achieves that by using a combination of Rack Middleware and ActiveRecord.
|
6
6
|
|
7
7
|
---
|
8
8
|
|
@@ -11,22 +11,24 @@ Sandboxy allows you to use virtual data-oriented environments inside a Rails app
|
|
11
11
|
* [Installation](#installation)
|
12
12
|
* [Usage](#usage)
|
13
13
|
* [Setup](#setup)
|
14
|
-
* [
|
15
|
-
* [
|
16
|
-
* [Sandboxy methods](#sandboxy-methods)
|
14
|
+
* [`sandboxy` methods](#sandboxy-methods)
|
15
|
+
* [Sandboxy class methods](#sandboxy-class-methods)
|
17
16
|
* [Switching environments](#switching-environments)
|
18
17
|
* [Sandbox & APIs](#sandbox--apis)
|
18
|
+
* [Configuration](#configuration)
|
19
|
+
* [Testing](#testing)
|
20
|
+
* [Test Coverage](#test-coverage)
|
19
21
|
* [To Do](#to-do)
|
20
22
|
* [Contributing](#contributing)
|
21
23
|
* [Contributors](#contributors)
|
22
|
-
* [Semantic
|
24
|
+
* [Semantic versioning](#semantic-versioning)
|
23
25
|
* [License](#license)
|
24
26
|
|
25
27
|
---
|
26
28
|
|
27
29
|
## Installation
|
28
30
|
|
29
|
-
Sandboxy works with Rails
|
31
|
+
Sandboxy works with Rails 5.0 onwards. You can add it to your `Gemfile` with:
|
30
32
|
|
31
33
|
```ruby
|
32
34
|
gem 'sandboxy'
|
@@ -43,27 +45,17 @@ Or install it yourself as:
|
|
43
45
|
If you always want to be up to date fetch the latest from GitHub in your `Gemfile`:
|
44
46
|
|
45
47
|
```ruby
|
46
|
-
gem 'sandboxy', github: '
|
48
|
+
gem 'sandboxy', github: 'jonhue/sandboxy'
|
47
49
|
```
|
48
50
|
|
49
51
|
Now run the generator:
|
50
52
|
|
51
53
|
$ rails g sandboxy
|
52
54
|
|
53
|
-
You can specify your applications default environment by passing `--default live` or `--default sandbox`. Learn more about switching environments [here](#switching-environments).
|
54
|
-
|
55
|
-
To set that your app should retain it's environment at runtime on new requests pass `--retain_environment true`.
|
56
|
-
|
57
|
-
You can always update your [configuration](#configuration) later.
|
58
|
-
|
59
55
|
To wrap things up, migrate the changes into your database:
|
60
56
|
|
61
57
|
$ rails db:migrate
|
62
58
|
|
63
|
-
**Note:** Use `rake db:migrate` instead if you run Rails < 5.
|
64
|
-
|
65
|
-
This will create a configuration file under `config/sandboxy.yml` as well as a migration file and the `Sandbox` model.
|
66
|
-
|
67
59
|
## Usage
|
68
60
|
|
69
61
|
### Setup
|
@@ -76,7 +68,7 @@ class Foo < ApplicationRecord
|
|
76
68
|
end
|
77
69
|
```
|
78
70
|
|
79
|
-
In most use cases you would want to add sandboxy to a lot of ActiveRecord models if not all. To simplify that you could create a new class and let all your models inherit from it:
|
71
|
+
In most use cases you would want to add `sandboxy` to a lot of ActiveRecord models if not all. To simplify that you could create a new class and let all your models inherit from it:
|
80
72
|
|
81
73
|
```ruby
|
82
74
|
class SharedSandbox < ApplicationRecord
|
@@ -87,13 +79,7 @@ class Foo < SharedSandbox
|
|
87
79
|
end
|
88
80
|
```
|
89
81
|
|
90
|
-
###
|
91
|
-
|
92
|
-
In `config/sandboxy.yml` you define your app's default environment. This can be either set to `live` or `sandbox`. It defaults to `live`.
|
93
|
-
|
94
|
-
Now this default gets refreshed before every new request. To retain any environment you [switched in at runtime](#switching-environments), you need to set `retain_environment` to `true`. Defaults to `false`.
|
95
|
-
|
96
|
-
### Sandboxed methods
|
82
|
+
### `sandboxy` methods
|
97
83
|
|
98
84
|
By default you can only access records belonging to the current environment (`live` or `sandbox`):
|
99
85
|
|
@@ -129,22 +115,22 @@ foo.make_sandboxed
|
|
129
115
|
foo.sandboxed? # => true
|
130
116
|
```
|
131
117
|
|
132
|
-
### Sandboxy methods
|
118
|
+
### `Sandboxy` class methods
|
133
119
|
|
134
120
|
To access your default environment setting:
|
135
121
|
|
136
122
|
```ruby
|
137
|
-
Sandboxy.environment # => 'live' / 'sandbox'
|
138
|
-
Sandboxy.sandbox? # => true / false
|
139
|
-
Sandboxy.live? # => true / false
|
123
|
+
Sandboxy.configuration.environment # => 'live' / 'sandbox'
|
124
|
+
Sandboxy.configuration.sandbox? # => true / false
|
125
|
+
Sandboxy.configuration.live? # => true / false
|
140
126
|
```
|
141
127
|
|
142
|
-
**Note:** `Sandboxy.environment` does *NOT* return the apps current environment. For that use the [`$sandbox` variable](#switching-environments) instead.
|
128
|
+
**Note:** `Sandboxy.configuration.environment` does *NOT* return the apps current environment. For that use the [`$sandbox` variable](#switching-environments) instead.
|
143
129
|
|
144
|
-
You can also access whether your app retains your environment throughout
|
130
|
+
You can also access whether your app retains your environment throughout requests:
|
145
131
|
|
146
132
|
```ruby
|
147
|
-
Sandboxy.retain_environment # => true / false
|
133
|
+
Sandboxy.configuration.retain_environment # => true / false
|
148
134
|
```
|
149
135
|
|
150
136
|
### Switching environments
|
@@ -161,9 +147,53 @@ Whenever you authenticate your API's consumer, just make sure to set the `$sandb
|
|
161
147
|
|
162
148
|
---
|
163
149
|
|
150
|
+
## Configuration
|
151
|
+
|
152
|
+
You can configure Sandboxy by passing a block to `configure`. This can be done in `config/initializers/sandboxy.rb`:
|
153
|
+
|
154
|
+
```ruby
|
155
|
+
Sandboxy.configure do |config|
|
156
|
+
config.environment = 'sandbox'
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
**`environment`** Set your environment default: Must be either `live` or `sandbox`. This is the environment that your app boots with. By default it gets refreshed with every new request to your server. Defaults to `'live'`.
|
161
|
+
|
162
|
+
**`retain_environment`** Specify whether to retain your current app environment on new requests. If set to `true`, your app will only load your environment default when starting. Every additional switch of your environment at runtime will then not be automatically resolved to your environment default on a new request. Takes a boolean. Defaults to `false`.
|
163
|
+
|
164
|
+
---
|
165
|
+
|
166
|
+
## Testing
|
167
|
+
|
168
|
+
Tests are written with Shoulda on top of `Test::Unit` with Factory Girl being used instead of fixtures. Tests are run using rake.
|
169
|
+
|
170
|
+
1. Fork this repository
|
171
|
+
2. Clone your forked git locally
|
172
|
+
3. Install dependencies
|
173
|
+
|
174
|
+
`$ bundle install`
|
175
|
+
|
176
|
+
4. Run tests
|
177
|
+
|
178
|
+
`$ rake test`
|
179
|
+
|
180
|
+
### Test Coverage
|
181
|
+
|
182
|
+
Test coverage can be calculated using SimpleCov. Make sure you have the [simplecov gem](https://github.com/colszowka/simplecov) installed.
|
183
|
+
|
184
|
+
1. Uncomment SimpleCov in the Gemfile
|
185
|
+
2. Uncomment the relevant section in `test/test_helper.rb`
|
186
|
+
3. Run tests
|
187
|
+
|
188
|
+
`$ rake test`
|
189
|
+
|
190
|
+
---
|
191
|
+
|
164
192
|
## To Do
|
165
193
|
|
166
|
-
|
194
|
+
[Here](https://github.com/jonhue/sandboxy/projects/1) is the full list of current projects.
|
195
|
+
|
196
|
+
To propose your ideas, initiate the discussion by adding a [new issue](https://github.com/jonhue/sandboxy/issues/new).
|
167
197
|
|
168
198
|
---
|
169
199
|
|
@@ -171,13 +201,13 @@ Whenever you authenticate your API's consumer, just make sure to set the `$sandb
|
|
171
201
|
|
172
202
|
We hope that you will consider contributing to Sandboxy. Please read this short overview for some information about how to get started:
|
173
203
|
|
174
|
-
[Learn more about contributing to this repository](https://github.com/
|
204
|
+
[Learn more about contributing to this repository](https://github.com/jonhue/sandboxy/blob/master/CONTRIBUTING.md), [Code of Conduct](https://github.com/jonhue/sandboxy/blob/master/CODE_OF_CONDUCT.md)
|
175
205
|
|
176
206
|
### Contributors
|
177
207
|
|
178
208
|
Give the people some :heart: who are working on this project. See them all at:
|
179
209
|
|
180
|
-
https://github.com/
|
210
|
+
https://github.com/jonhue/sandboxy/graphs/contributors
|
181
211
|
|
182
212
|
### Semantic Versioning
|
183
213
|
|
@@ -187,7 +217,7 @@ Sandboxy follows Semantic Versioning 2.0 as defined at http://semver.org.
|
|
187
217
|
|
188
218
|
MIT License
|
189
219
|
|
190
|
-
Copyright (c) 2017
|
220
|
+
Copyright (c) 2017 Jonas Hübotter
|
191
221
|
|
192
222
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
193
223
|
of this software and associated documentation files (the "Software"), to deal
|
data/Rakefile
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Books
|
2
|
+
class API < Grape::API
|
3
|
+
|
4
|
+
version 'v1', using: :path, vendor: 'books'
|
5
|
+
format :json
|
6
|
+
|
7
|
+
helpers do
|
8
|
+
def authenticate! access_token
|
9
|
+
if current_app ||= ::Application.find_by(access_token: access_token)
|
10
|
+
$sandbox = false
|
11
|
+
elsif current_app ||= ::Application.find_by(sandbox_access_token: access_token)
|
12
|
+
$sandbox = true
|
13
|
+
else
|
14
|
+
error!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
rescue_from :all
|
20
|
+
|
21
|
+
resource :books do
|
22
|
+
params do
|
23
|
+
requires :access_token, String
|
24
|
+
end
|
25
|
+
|
26
|
+
get :index do
|
27
|
+
authenticate! params[:access_token]
|
28
|
+
::Book.all.limit(5)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
class ApplicationsController < ApplicationController
|
2
|
+
before_action :set_application, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /applications
|
5
|
+
# GET /applications.json
|
6
|
+
def index
|
7
|
+
@applications = Application.all
|
8
|
+
end
|
9
|
+
|
10
|
+
# GET /applications/1
|
11
|
+
# GET /applications/1.json
|
12
|
+
def show
|
13
|
+
end
|
14
|
+
|
15
|
+
# GET /applications/new
|
16
|
+
def new
|
17
|
+
@application = Application.new
|
18
|
+
end
|
19
|
+
|
20
|
+
# GET /applications/1/edit
|
21
|
+
def edit
|
22
|
+
end
|
23
|
+
|
24
|
+
# POST /applications
|
25
|
+
# POST /applications.json
|
26
|
+
def create
|
27
|
+
@application = Application.new(application_params)
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
if @application.save
|
31
|
+
format.html { redirect_to @application, notice: 'Application was successfully created.' }
|
32
|
+
format.json { render :show, status: :created, location: @application }
|
33
|
+
else
|
34
|
+
format.html { render :new }
|
35
|
+
format.json { render json: @application.errors, status: :unprocessable_entity }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# PATCH/PUT /applications/1
|
41
|
+
# PATCH/PUT /applications/1.json
|
42
|
+
def update
|
43
|
+
respond_to do |format|
|
44
|
+
if @application.update(application_params)
|
45
|
+
format.html { redirect_to @application, notice: 'Application was successfully updated.' }
|
46
|
+
format.json { render :show, status: :ok, location: @application }
|
47
|
+
else
|
48
|
+
format.html { render :edit }
|
49
|
+
format.json { render json: @application.errors, status: :unprocessable_entity }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# DELETE /applications/1
|
55
|
+
# DELETE /applications/1.json
|
56
|
+
def destroy
|
57
|
+
@application.destroy
|
58
|
+
respond_to do |format|
|
59
|
+
format.html { redirect_to applications_url, notice: 'Application was successfully destroyed.' }
|
60
|
+
format.json { head :no_content }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
# Use callbacks to share common setup or constraints between actions.
|
66
|
+
def set_application
|
67
|
+
@application = Application.find(params[:id])
|
68
|
+
end
|
69
|
+
|
70
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
71
|
+
def application_params
|
72
|
+
params.fetch(:application, {})
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class AuthorsController < ApplicationController
|
2
|
+
before_action :set_author, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /authors
|
5
|
+
# GET /authors.json
|
6
|
+
def index
|
7
|
+
$sandbox = session[:sandbox]
|
8
|
+
@authors = Author.all
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /authors/1
|
12
|
+
# GET /authors/1.json
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /authors/new
|
17
|
+
def new
|
18
|
+
$sandbox = session[:sandbox]
|
19
|
+
@author = Author.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /authors/1/edit
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
# POST /authors
|
27
|
+
# POST /authors.json
|
28
|
+
def create
|
29
|
+
$sandbox = session[:sandbox]
|
30
|
+
@author = Author.new(author_params)
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
if @author.save
|
34
|
+
format.html { redirect_to @author, notice: 'Author was successfully created.' }
|
35
|
+
format.json { render :show, status: :created, location: @author }
|
36
|
+
else
|
37
|
+
format.html { render :new }
|
38
|
+
format.json { render json: @author.errors, status: :unprocessable_entity }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# PATCH/PUT /authors/1
|
44
|
+
# PATCH/PUT /authors/1.json
|
45
|
+
def update
|
46
|
+
respond_to do |format|
|
47
|
+
if @author.update(author_params)
|
48
|
+
format.html { redirect_to @author, notice: 'Author was successfully updated.' }
|
49
|
+
format.json { render :show, status: :ok, location: @author }
|
50
|
+
else
|
51
|
+
format.html { render :edit }
|
52
|
+
format.json { render json: @author.errors, status: :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# DELETE /authors/1
|
58
|
+
# DELETE /authors/1.json
|
59
|
+
def destroy
|
60
|
+
@author.destroy
|
61
|
+
respond_to do |format|
|
62
|
+
format.html { redirect_to authors_url, notice: 'Author was successfully destroyed.' }
|
63
|
+
format.json { head :no_content }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
# Use callbacks to share common setup or constraints between actions.
|
69
|
+
def set_author
|
70
|
+
@author = Author.find(params[:id])
|
71
|
+
end
|
72
|
+
|
73
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
74
|
+
def author_params
|
75
|
+
params.fetch(:author, {})
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class BooksController < ApplicationController
|
2
|
+
before_action :set_book, only: [:show, :edit, :update, :destroy]
|
3
|
+
|
4
|
+
# GET /books
|
5
|
+
# GET /books.json
|
6
|
+
def index
|
7
|
+
$sandbox = session[:sandbox]
|
8
|
+
@books = Book.all
|
9
|
+
end
|
10
|
+
|
11
|
+
# GET /books/1
|
12
|
+
# GET /books/1.json
|
13
|
+
def show
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /books/new
|
17
|
+
def new
|
18
|
+
$sandbox = session[:sandbox]
|
19
|
+
@book = Book.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /books/1/edit
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
# POST /books
|
27
|
+
# POST /books.json
|
28
|
+
def create
|
29
|
+
$sandbox = session[:sandbox]
|
30
|
+
@book = Book.new(book_params)
|
31
|
+
|
32
|
+
respond_to do |format|
|
33
|
+
if @book.save
|
34
|
+
format.html { redirect_to @book, notice: 'Book was successfully created.' }
|
35
|
+
format.json { render :show, status: :created, location: @book }
|
36
|
+
else
|
37
|
+
format.html { render :new }
|
38
|
+
format.json { render json: @book.errors, status: :unprocessable_entity }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# PATCH/PUT /books/1
|
44
|
+
# PATCH/PUT /books/1.json
|
45
|
+
def update
|
46
|
+
respond_to do |format|
|
47
|
+
if @book.update(book_params)
|
48
|
+
format.html { redirect_to @book, notice: 'Book was successfully updated.' }
|
49
|
+
format.json { render :show, status: :ok, location: @book }
|
50
|
+
else
|
51
|
+
format.html { render :edit }
|
52
|
+
format.json { render json: @book.errors, status: :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# DELETE /books/1
|
58
|
+
# DELETE /books/1.json
|
59
|
+
def destroy
|
60
|
+
@book.destroy
|
61
|
+
respond_to do |format|
|
62
|
+
format.html { redirect_to books_url, notice: 'Book was successfully destroyed.' }
|
63
|
+
format.json { head :no_content }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
# Use callbacks to share common setup or constraints between actions.
|
69
|
+
def set_book
|
70
|
+
@book = Book.find(params[:id])
|
71
|
+
end
|
72
|
+
|
73
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
74
|
+
def book_params
|
75
|
+
params.fetch(:book, {})
|
76
|
+
end
|
77
|
+
end
|