basic_crud 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.idea/.gitignore +8 -0
- data/.idea/basic_crud.iml +74 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +8 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +96 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +6 -0
- data/basic_crud.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/basic_crud/version.rb +3 -0
- data/lib/basic_crud.rb +80 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 954739585bc309af7684f9bc81b05378b7fce9593af97d25320724de5f980b10
|
4
|
+
data.tar.gz: e120586482ac6995c045dd9188100407d3dd97009c7c02ae5a4a43fcbee3b429
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3813e60154f2c108ea5d486a3131d21a50e6a985e555565b0c8631d2496c2ce75f08b25c34f039c20182b5a84fe841f2881b0200f2d3b833e9cd1c2d8455174
|
7
|
+
data.tar.gz: 4cc76a7586ee1b79f618279b7f5456b32192d1eebc64ca22805b03e1d3c5ba3e430fb0536ecfe679e99d22dc5fe504752f48f2ca69aa4ad5b805fcf302c7424e
|
data/.gitignore
ADDED
data/.idea/.gitignore
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="inheritedJdk" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v6.1.4.1, rbenv: 2.6.5) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="actionview (v6.1.4.1, rbenv: 2.6.5) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.1.4.1, rbenv: 2.6.5) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, rbenv: 2.6.5) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.1.4, rbenv: 2.6.5) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.9, rbenv: 2.6.5) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, rbenv: 2.6.5) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.4.4, rbenv: 2.6.5) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, rbenv: 2.6.5) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.10, rbenv: 2.6.5) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.12.0, rbenv: 2.6.5) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, rbenv: 2.6.5) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.6.1, rbenv: 2.6.5) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.4, rbenv: 2.6.5) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.12.3, rbenv: 2.6.5) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.5.2, rbenv: 2.6.5) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, rbenv: 2.6.5) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, rbenv: 2.6.5) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, rbenv: 2.6.5) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.1, rbenv: 2.6.5) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="railties (v6.1.4.1, rbenv: 2.6.5) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v12.3.3, rbenv: 2.6.5) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.10.0, rbenv: 2.6.5) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.10.1, rbenv: 2.6.5) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.10.1, rbenv: 2.6.5) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.10.2, rbenv: 2.6.5) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-rails (v5.0.2, rbenv: 2.6.5) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.10.2, rbenv: 2.6.5) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v1.1.0, rbenv: 2.6.5) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, rbenv: 2.6.5) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.4.2, rbenv: 2.6.5) [gem]" level="application" />
|
45
|
+
</component>
|
46
|
+
<component name="RakeTasksCache">
|
47
|
+
<option name="myRootTask">
|
48
|
+
<RakeTaskImpl id="rake">
|
49
|
+
<subtasks>
|
50
|
+
<RakeTaskImpl description="Build basic_crud-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
51
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
52
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
53
|
+
<RakeTaskImpl description="Build and install basic_crud-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
54
|
+
<RakeTaskImpl id="install">
|
55
|
+
<subtasks>
|
56
|
+
<RakeTaskImpl description="Build and install basic_crud-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
57
|
+
</subtasks>
|
58
|
+
</RakeTaskImpl>
|
59
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push basic_crud-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
60
|
+
<RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
|
61
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
62
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
63
|
+
<RakeTaskImpl id="release">
|
64
|
+
<subtasks>
|
65
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
66
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
67
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
68
|
+
</subtasks>
|
69
|
+
</RakeTaskImpl>
|
70
|
+
</subtasks>
|
71
|
+
</RakeTaskImpl>
|
72
|
+
</option>
|
73
|
+
</component>
|
74
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/basic_crud.iml" filepath="$PROJECT_DIR$/.idea/basic_crud.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="VcsDirectoryMappings">
|
4
|
+
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
5
|
+
<mapping directory="$PROJECT_DIR$/basic_crud" vcs="Git" />
|
6
|
+
<mapping directory="$PROJECT_DIR$/spec/dummy" vcs="Git" />
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
basic_crud (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
actionpack (6.1.4.1)
|
10
|
+
actionview (= 6.1.4.1)
|
11
|
+
activesupport (= 6.1.4.1)
|
12
|
+
rack (~> 2.0, >= 2.0.9)
|
13
|
+
rack-test (>= 0.6.3)
|
14
|
+
rails-dom-testing (~> 2.0)
|
15
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
16
|
+
actionview (6.1.4.1)
|
17
|
+
activesupport (= 6.1.4.1)
|
18
|
+
builder (~> 3.1)
|
19
|
+
erubi (~> 1.4)
|
20
|
+
rails-dom-testing (~> 2.0)
|
21
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
22
|
+
activesupport (6.1.4.1)
|
23
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
24
|
+
i18n (>= 1.6, < 2)
|
25
|
+
minitest (>= 5.1)
|
26
|
+
tzinfo (~> 2.0)
|
27
|
+
zeitwerk (~> 2.3)
|
28
|
+
builder (3.2.4)
|
29
|
+
concurrent-ruby (1.1.9)
|
30
|
+
crass (1.0.6)
|
31
|
+
diff-lcs (1.4.4)
|
32
|
+
erubi (1.10.0)
|
33
|
+
i18n (1.8.10)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
loofah (2.12.0)
|
36
|
+
crass (~> 1.0.2)
|
37
|
+
nokogiri (>= 1.5.9)
|
38
|
+
method_source (1.0.0)
|
39
|
+
mini_portile2 (2.6.1)
|
40
|
+
minitest (5.14.4)
|
41
|
+
nokogiri (1.12.3)
|
42
|
+
mini_portile2 (~> 2.6.1)
|
43
|
+
racc (~> 1.4)
|
44
|
+
racc (1.5.2)
|
45
|
+
rack (2.2.3)
|
46
|
+
rack-test (1.1.0)
|
47
|
+
rack (>= 1.0, < 3)
|
48
|
+
rails-dom-testing (2.0.3)
|
49
|
+
activesupport (>= 4.2.0)
|
50
|
+
nokogiri (>= 1.6)
|
51
|
+
rails-html-sanitizer (1.4.1)
|
52
|
+
loofah (~> 2.3)
|
53
|
+
railties (6.1.4.1)
|
54
|
+
actionpack (= 6.1.4.1)
|
55
|
+
activesupport (= 6.1.4.1)
|
56
|
+
method_source
|
57
|
+
rake (>= 0.13)
|
58
|
+
thor (~> 1.0)
|
59
|
+
rake (12.3.3)
|
60
|
+
rspec (3.10.0)
|
61
|
+
rspec-core (~> 3.10.0)
|
62
|
+
rspec-expectations (~> 3.10.0)
|
63
|
+
rspec-mocks (~> 3.10.0)
|
64
|
+
rspec-core (3.10.1)
|
65
|
+
rspec-support (~> 3.10.0)
|
66
|
+
rspec-expectations (3.10.1)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.10.0)
|
69
|
+
rspec-mocks (3.10.2)
|
70
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
+
rspec-support (~> 3.10.0)
|
72
|
+
rspec-rails (5.0.2)
|
73
|
+
actionpack (>= 5.2)
|
74
|
+
activesupport (>= 5.2)
|
75
|
+
railties (>= 5.2)
|
76
|
+
rspec-core (~> 3.10)
|
77
|
+
rspec-expectations (~> 3.10)
|
78
|
+
rspec-mocks (~> 3.10)
|
79
|
+
rspec-support (~> 3.10)
|
80
|
+
rspec-support (3.10.2)
|
81
|
+
thor (1.1.0)
|
82
|
+
tzinfo (2.0.4)
|
83
|
+
concurrent-ruby (~> 1.0)
|
84
|
+
zeitwerk (2.4.2)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
ruby
|
88
|
+
|
89
|
+
DEPENDENCIES
|
90
|
+
basic_crud!
|
91
|
+
rake (~> 12.0)
|
92
|
+
rspec
|
93
|
+
rspec-rails
|
94
|
+
|
95
|
+
BUNDLED WITH
|
96
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Mathias Rong
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# BasicCrud
|
2
|
+
|
3
|
+
Contains base (overridable) logic for default controller actions index/show/edit/create/update/destroy
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'basic_crud'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install basic_crud
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In the (empty) controller, include basic_crud
|
24
|
+
```ruby
|
25
|
+
class ApplicationController < ActionController::Base
|
26
|
+
include BasicCrud
|
27
|
+
end
|
28
|
+
```
|
29
|
+
In this example, all controllers will inherit BasicCrud functionality.
|
30
|
+
You can also just include the Module into certain controllers.
|
31
|
+
|
32
|
+
Objects are stored in `@record` or `@records` and accessible in the views.
|
33
|
+
|
34
|
+
If you need additional functionality, e.g. special logic for your index page, just override `def index .. end`.
|
35
|
+
Be sure to store your results in `@record` or `@records`
|
36
|
+
|
37
|
+
You can also call the super method and inject a block:
|
38
|
+
```ruby
|
39
|
+
def index
|
40
|
+
super do
|
41
|
+
# your logic here, e.g. @record.attribute1 = "static string"
|
42
|
+
# your logic is called between record fetching and displaying the view
|
43
|
+
end
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
## Tests
|
48
|
+
|
49
|
+
Specs are written for a dummy rails app, run `rspec spec` to run the specs.
|
50
|
+
Because this gem needs controllers, the specs are located at `spec/dummy/spec`
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rongworks/basic_crud.
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/basic_crud.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/basic_crud/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "basic_crud"
|
5
|
+
spec.version = BasicCrud::VERSION
|
6
|
+
spec.authors = ["rongworks"]
|
7
|
+
spec.email = ["info@rongworks.de"]
|
8
|
+
|
9
|
+
spec.summary = "Adds Basic Crud functionality to any controller"
|
10
|
+
spec.description = "Contains base (overridable) logic for default controller actions index/show/edit/create/update/destroy"
|
11
|
+
spec.homepage = "https://github.com/rongworks/basic_crud"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
#spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
19
|
+
#spec.metadata["changelog_uri"] = "#{spec.homepage}/chanhelog.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency 'rspec-rails'
|
31
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "basic_crud"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/basic_crud.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
require "basic_crud/version"
|
2
|
+
|
3
|
+
module BasicCrud
|
4
|
+
def index
|
5
|
+
@records = model.all
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html { render :index }
|
9
|
+
format.json { render json: @records }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def show
|
14
|
+
@record = fetch_record_by_param
|
15
|
+
|
16
|
+
respond_to do |format|
|
17
|
+
format.html { render :show }
|
18
|
+
format.json { render json: @record }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def edit
|
23
|
+
@record = fetch_record_by_param
|
24
|
+
end
|
25
|
+
|
26
|
+
def new
|
27
|
+
@record = model.new
|
28
|
+
end
|
29
|
+
|
30
|
+
def create
|
31
|
+
@record = model.new(restricted_params)
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
if @record.save
|
35
|
+
format.html { redirect_to action: :index, notice: "#{model} was successfully created." }
|
36
|
+
format.json { render @record, status: :created }
|
37
|
+
else
|
38
|
+
format.html { render :new }
|
39
|
+
format.json { render json: @record.errors, status: :unprocessable_entity }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def update
|
45
|
+
@record = fetch_record_by_param
|
46
|
+
respond_to do |format|
|
47
|
+
if @record.update(restricted_params)
|
48
|
+
format.html { redirect_to @record, notice: "#{model} was successfully updated." }
|
49
|
+
format.json { render @record, status: :ok }
|
50
|
+
else
|
51
|
+
format.html { render :edit }
|
52
|
+
format.json { render json: @record.errors, status: :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def destroy
|
58
|
+
@record = fetch_record_by_param
|
59
|
+
@record.destroy
|
60
|
+
respond_to do |format|
|
61
|
+
format.html { redirect_to action: :index, notice: "#{model} was successfully destroyed." }
|
62
|
+
format.json { head :no_content }
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# default record by id for show, edit, ..
|
67
|
+
def fetch_record_by_param
|
68
|
+
model.find(params[:id])
|
69
|
+
end
|
70
|
+
|
71
|
+
# Derive model from ControllerClass (ThingsController => Thing)
|
72
|
+
def model
|
73
|
+
self.controller_name.classify.constantize
|
74
|
+
end
|
75
|
+
|
76
|
+
# Override this method to allow model attributes
|
77
|
+
def restricted_params
|
78
|
+
params.require(self.controller_name.classify.underscore.to_sym).permit([])
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: basic_crud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- rongworks
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Contains base (overridable) logic for default controller actions index/show/edit/create/update/destroy
|
28
|
+
email:
|
29
|
+
- info@rongworks.de
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".idea/.gitignore"
|
36
|
+
- ".idea/basic_crud.iml"
|
37
|
+
- ".idea/misc.xml"
|
38
|
+
- ".idea/modules.xml"
|
39
|
+
- ".idea/vcs.xml"
|
40
|
+
- ".rspec"
|
41
|
+
- ".travis.yml"
|
42
|
+
- Gemfile
|
43
|
+
- Gemfile.lock
|
44
|
+
- LICENSE.txt
|
45
|
+
- README.md
|
46
|
+
- Rakefile
|
47
|
+
- basic_crud.gemspec
|
48
|
+
- bin/console
|
49
|
+
- bin/setup
|
50
|
+
- lib/basic_crud.rb
|
51
|
+
- lib/basic_crud/version.rb
|
52
|
+
homepage: https://github.com/rongworks/basic_crud
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata:
|
56
|
+
homepage_uri: https://github.com/rongworks/basic_crud
|
57
|
+
source_code_uri: https://github.com/rongworks/basic_crud
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.3.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.2.3
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Adds Basic Crud functionality to any controller
|
77
|
+
test_files: []
|