履歴: ソフトウェア/rails/PaperTrail+ActiveScaffold
各行は、その日時に書かれた内容です。追加・削除は、1 つ前の版との行数の差です (全 19 版)。「差分」は比較する版、「基準」は比べる相手の版を選びます
| 日時 | タイトル | 文字数 | 追加 | 削除 | 内容 | 差分 | 基準 |
|---|---|---|---|---|---|---|---|
| 2017/11/29 23:51:31 | ソフトウェア/rails/PaperTrail+ActiveScaffold 最新版 | 65,862 | +1 | -1 | 表示 | 差分 | — |
| 2017/11/29 23:51:31 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 65,868 | +142 | -40 | 表示 | 差分 | 選択 |
| 2017/11/20 22:46:29 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 62,621 | +28 | -7 | 表示 | 差分 | 選択 |
| 2017/11/17 4:40:23 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 62,164 | +439 | -168 | 表示 | 差分 | 選択 |
| 2017/11/11 0:33:35 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 56,254 | +62 | -0 | 表示 | 表示中 | 選択 |
| 2017/11/10 15:30:30 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 54,775 | +234 | -0 | 表示 | 差分 | 選択 |
| 2017/7/21 3:01:44 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 45,642 | +217 | -0 | 表示 | 差分 | 選択 |
| 2014/10/28 2:23:29 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,600 | +18 | -1 | 表示 | 差分 | 選択 |
| 2014/5/20 12:30:48 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,301 | +3 | -1 | 表示 | 差分 | 選択 |
| 2014/5/19 7:59:00 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,274 | +1 | -1 | 表示 | 差分 | 基準 |
| 2014/5/16 12:35:23 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 37,268 | +141 | -13 | 表示 | 差分 | 選択 |
| 2014/5/16 2:38:10 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 33,839 | +118 | -1 | 表示 | 差分 | 選択 |
| 2014/5/16 1:02:59 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 30,813 | +225 | -26 | 表示 | 差分 | 選択 |
| 2014/5/1 16:06:00 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 25,360 | +329 | -0 | 表示 | 差分 | 選択 |
| 2014/4/30 13:35:06 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 16,966 | +264 | -0 | 表示 | 差分 | 選択 |
| 2014/4/28 1:10:44 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,805 | +4 | -0 | 表示 | 差分 | 選択 |
| 2014/4/25 2:51:34 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,732 | +2 | -2 | 表示 | 差分 | 選択 |
| 2014/4/24 15:21:55 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 10,728 | +382 | -1 | 表示 | 差分 | 選択 |
| 2014/4/24 11:01:35 | ソフトウェア/rails/PaperTrail+ActiveScaffold | 1,131 | — | — | 表示 | — | 選択 |
基準: ソフトウェア/rails/PaperTrail+ActiveScaffold (2014/5/19 7:59:00) → 比較: ソフトウェア/rails/PaperTrail+ActiveScaffold (2017/11/11 0:33:35)
@@ -512,6 +512,22 @@
とすることで、削除済みのアイテムを表示できました。
+*** 2014-10-28 追記 [#t9278ff4]
+
+上記だと親レコードからのリンクで子レコードの一覧を表示する際などに
+「親レコードの子である」という制約も unscoped で外れてしまい、
+全件が表示されてしまうという問題が発生することが分かりました。
+
+ LANG:ruby
+ super.unscoped
+
+の代わりに
+
+ LANG:ruby
+ nested? ? super : super.unscoped
+
+とするのが良いようでした。
+
** histories を一覧 [#s25fec03]
上記だけだと histories のリンクで Request Failed となってしまいます。
@@ -756,6 +772,8 @@
# 2014.05.16 build, as_tpsf_routes を実装した
# ヘルパにユーティリティ関数を定義した
# as_tpsf_routes のコードをファイル末尾に取り込んだ
+ # 2014.05.20 const_get 関連の改善
+ # 2014.10.28 nested リスト表示の際の検索条件を正しくした
#
module TrailedParanoidScaffold
@@ -830,7 +848,7 @@
# 削除済みのレコードも表示する
def beginning_of_chain
- super().unscoped
+ nested? ? super() : super().unscoped
end
# acts_as_paranoid で deleted_at が立てられたレコードを復帰させる
@@ -1019,8 +1037,9 @@
# TrailedParanoidScaffold::HistoriesController
# TrailedParanoidScaffold::HistoriesHelper
# を include する
- include Object.const_get "TrailedParanoidScaffold::" +
+ include TrailedParanoidScaffold.const_get(
(histories ? "Histories" : "") + controller_or_helper.classify
+ )
# モデル名も計算しておく
if controller_or_helper == "controller"
@@ -1458,6 +1477,519 @@
リンクをしない設定はこれで正しいんだろうか?~
[[ソースコード>https://github.com/activescaffold/active_scaffold/blob/5066df89173db70f5e96f6a89f175bee7ca9061c/lib/active_scaffold/data_structures/column.rb]] を読んでも、どうするのが正式なのかが分からない???
+* ruby 2.4.0p0 + Rails5 環境では動かなくなってしまいました [#ufe1d06d]
+
+いくつか問題があるようです。
+
+- とりあえず turbolinks5 は off にした
+- histories のリンクが機能していない
+- edit → update で失敗する
+
+** histories のリンクが機能していない [#aafbacd1]
+
+500 Internal Server Error が出てしまいました。
+
+ LANG:console
+ Processing by Admin::Account::HistoriesController#index as JS
+ Parameters: {"association"=>"histories", "parent_scaffold"=>"admin/accounts", "adapter"=>"_list_inline_adapter", "account_id"=>"1"}
+ Account Load (0.3ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."deleted_at" IS NULL AND "accounts"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
+ Account Load (0.2ms) SELECT "accounts".* FROM "accounts" WHERE "accounts"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
+ Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.5ms)
+
+ NoMethodError (undefined method `[]' for nil:NilClass):
+
+ /home/takeuchi/.rvm/gems/ruby-2.4.0@ICSPM25/bundler/gems/active_scaffold-ab5840e57e91/lib/active_scaffold/data_structures/nested_info.rb:109:in `default_sorting'
+ /home/takeuchi/.rvm/gems/ruby-2.4.0@ICSPM25/bundler/gems/active_scaffold-ab5840e57e91/lib/active_scaffold/data_structures/nested_info.rb:102:in `sorted?'
+ /home/takeuchi/.rvm/gems/ruby-2.4.0@ICSPM25/bundler/gems/active_scaffold-ab5840e57e91/lib/active_scaffold/actions/nested.rb:39:in `configure_nested'
+ activesupport (5.1.2) lib/active_support/callbacks.rb:413:in `block in make_lambda'
+ activesupport (5.1.2) lib/active_support/callbacks.rb:197:in `block (2 levels) in halting'
+ ...
+
+https://github.com/osamutake/active_scaffold/blob/master/lib/active_scaffold/data_structures/nested_info.rb#L109
+
+ LANG:ruby
+ def sorted?(chain)
+ default_sorting(chain).present?
+ end
+
+ def default_sorting(chain)
+ return @default_sorting if defined? @default_sorting
+ if association.scope.is_a?(Proc) && chain.respond_to?(:values)
+ @default_sorting = chain.values[:order]
+ @default_sorting = @default_sorting.map(&:to_sql) if @default_sorting[0].is_a? Arel::Nodes::Node
+ @default_sorting = @default_sorting.join(', ')
+ end
+ end
+
+の真ん中の @default_sorting[0].is_a? Arel::Nodes::Node で、
+@default_sorting が nil になって失敗しているみたい
+
+上記の chain は
+
+https://github.com/osamutake/active_scaffold/blob/master/lib/active_scaffold/actions/nested.rb#L39
+
+によると
+
+https://github.com/osamutake/active_scaffold/blob/master/lib/active_scaffold/actions/nested.rb#L82
+
+の beginning_of_chain で作られているのだけれど、
+必ずしも :order が設定されていない可能性がある、ということなのかも?
+
+byebug 仕込んで見てみると、
+
+ LANG:console
+ [103, 112] in /home/takeuchi/.rvm/gems/ruby-2.4.0@ICSPM25/bundler/gems/active_scaffold-ab5840e57e91/lib/active_scaffold/data_structures/nested_info.rb
+ 103: end
+ 104:
+ 105: def default_sorting(chain)
+ 106: return @default_sorting if defined? @default_sorting
+ 107: byebug
+ => 108: if association.scope.is_a?(Proc) && chain.respond_to?(:values)
+ 109: @default_sorting = chain.values[:order]
+ 110: @default_sorting = @default_sorting.map(&:to_sql) if @default_sorting[0].is_a? Arel::Nodes::Node
+ 111: @default_sorting = @default_sorting.join(', ')
+ 112: end
+ (byebug) chain
+ CACHE Account::History Load (0.0ms) SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = ? AND (item_type = "Account") LIMIT ? [["item_id", 1], ["LIMIT", 11]]
+#<ActiveRecord::Associations::CollectionProxy [#<Account::History id: 1, item_type: "Account", item_id: 1, event: "create", whodunnit: nil, object: nil, created_at: "2017-07-13 00:39:52", object_changes: "---\nemail:\n- \n- takeuchi@bk.tsukuba.ac.jp\npassword...", transaction_id: 1>]>
+
+なので、確かに ORDER BY 節が存在しない。
+
+えーと・・・これ、以前のバージョンだとどうして動いてたんだ???
+
+あれ、ruby や Rails のバージョン違いじゃなくて、
+active_scaffold 自体のバージョンが上がっている問題なのかも???
+
+以前使っていた active_scaffold (3.4.39) だと、
+
+https://github.com/activescaffold/active_scaffold/blob/5c5c18ccaf28ef7ab6a4f0564912bb4e0fbb8e4f/lib/active_scaffold/data_structures/nested_info.rb#L121
+
+のようになっていて、全然違うコードだ。
+
+ # TODO: remove when rails 3 compatibility is removed
+
+というコメントが付いてある部分を何とかしようとして、バグが混入したのかもしれない?
+
+たぶん、以下のようにすれば良さそう。
+
+ LANG:ruby
+ def default_sorting(chain)
+ return @default_sorting if defined? @default_sorting
+ - if association.scope.is_a?(Proc) && chain.respond_to?(:values)
+ + if association.scope.is_a?(Proc) && chain.respond_to?(:values) && chain.values[:order]
+ @default_sorting = chain.values[:order]
+ @default_sorting = @default_sorting.map(&:to_sql) if @default_sorting[0].is_a? Arel::Nodes::Node
+ @default_sorting = @default_sorting.join(', ')
+ end
+ end
+
+とりあえず、それらしく動くことを確認。
+
+これでいいのかどうかよく分からないけど、一応、報告してみました。~
+https://github.com/activescaffold/active_scaffold/issues/560
+
+** edit → update で失敗する [#g2da7dc2]
+
+まず、なぜか更新ボタンを1回押しただけで同時に2つのリクエストが飛んでいる。
+
+ LANG:console
+ Started PATCH "/event/ICSPM25/ja/admin/invited_speakers/13?utf8=%E2%9C%93" for 127.0.0.1 at 2017-07-21 11:35:30 +0900
+ Started PATCH "/event/ICSPM25/ja/admin/invited_speakers/13?utf8=%E2%9C%93" for 127.0.0.1 at 2017-07-21 11:35:30 +0900
+ Processing by Admin::InvitedSpeakersController#update as JS
+ Processing by Admin::InvitedSpeakersController#update as JS
+
+form の submit に jquery_ujs のイベント
+
+ LANG:javascript
+ function(e) {
+ var form = $(this),
+ remote = rails.isRemote(form),
+ blankRequiredInputs,
+ nonBlankFileInputs;
+
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
+
+ // Skip other logic when required values are missing or file upload is present
+ if (form.attr('novalidate') === undefined) {
+ if (form.data('ujs:formnovalidate-button') === undefined) {
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector, false);
+ if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
+ return rails.stopEverything(e);
+ }
+ } else {
+ // Clear the formnovalidate in case the next button click is not on a formnovalidate button
+ // Not strictly necessary to do here, since it is also reset on each button click, but just to be certain
+ form.data('ujs:formnovalidate-button', undefined);
+ }
+ }
+
+ if (remote) {
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
+ if (nonBlankFileInputs) {
+ // Slight timeout so that the submit button gets properly serialized
+ // (make it easy for event handler to serialize form without disabled values)
+ setTimeout(function() {
+ rails.disableFormElements(form);
+ }, 13);
+ var aborted = rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
+
+ // Re-enable form elements if event bindings return false (canceling normal form submission)
+ if (!aborted) {
+ setTimeout(function() {
+ rails.enableFormElements(form);
+ }, 13);
+ }
+
+ return aborted;
+ }
+
+ rails.handleRemote(form);
+ return false;
+
+ } else {
+ // Slight timeout so that the submit button gets properly serialized
+ setTimeout(function() {
+ rails.disableFormElements(form);
+ }, 13);
+ }
+ }
+
+form の 更新ボタン の click に jquery_ujs の
+
+ LANG:javascript
+ function(event) {
+ var button = $(this);
+
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
+
+ // Register the pressed submit button
+ var name = button.attr('name'),
+ data = name ? {
+ name: name,
+ value: button.val()
+ } : null;
+
+ var form = button.closest('form');
+ if (form.length === 0) {
+ form = $('#' + button.attr('form'));
+ }
+ form.data('ujs:submit-button', data);
+
+ // Save attributes from button
+ form.data('ujs:formnovalidate-button', button.attr('formnovalidate'));
+ form.data('ujs:submit-button-formaction', button.attr('formaction'));
+ form.data('ujs:submit-button-formmethod', button.attr('formmethod'));
+ }
+
+あれ?jquery_ujs と rails-ujs ってのが両方入ってるけど、
+これっていいのか?
+
+http://qiita.com/itkrt2y/items/7e999836f460fb9c005d
+
+jquery_ujs を削ったらそもそも form が表示されなくなってしまった。
+
+rails-ujs を削ったら正しく動いた。
+
+えーと・・・どうなってるんだっけ?
+
+Gemfile を見直す必要がありそう。
+
+* Rails 5 でも動くようにしたい (2017-11) [#l94df97e]
+
+ruby, rails, bundler とも現時点での最新版を使ってみます。
+
+ LANG:console
+ $ rvm --version
+ rvm 1.26.11 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
+ $ cat .ruby-version
+ ruby-2.4.2
+ $ ruby --version
+ ruby 2.4.2p198 (2017-09-14 revision 59899) [i686-linux]
+ $ gem --version
+ 2.6.13
+ $ rails --version
+ Rails 5.1.4
+ $ bundler --version
+ Bundler version 1.16.0
+ $ rails new tpsf
+ ...
+
+ The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for.
+ Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java.
+ To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
+ ...
+
+ Bundle complete! 16 Gemfile dependencies, 70 gems now installed.
+ Use `bundle info [gemname]` to see where a bundled gem is installed.
+ run bundle exec spring binstub --all
+ * bin/rake: spring inserted
+ * bin/rails: spring inserted
+ $ git add .
+ $ git commit -m "initial commit"
+ $ jed Gemfile
+ - gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+ + #gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
+ +
+ + gem 'paper_trail'
+ + gem 'active_scaffold'
+ + gem 'paranoia'
+ $ bundle install
+ $ git commit -a -m "gem tzinfo-data removed / gems paper_trail, active_scaffold and paranoia installed"
+
+とりあえずインストール終了。
+
+** モデルの作成をしようとすると active_scaffold が文句を言う [#d02f64f5]
+
+仕方が無いので最新版をインストール
+
+ LANG:console
+ $ rails g active_scaffold Test name:string email:string
+ /home/osamu/.rvm/gems/ruby-2.4.2@album/gems/bundler-1.16.0/lib/bundler/runtime.rb:84:in `rescue in block (2 levels) in require':
+ There was an error while trying to load the gem 'active_scaffold'.
+ Gem Load Error is: This version of ActiveScaffold requires Rails 3.1 or higher.
+ Please use an earlier version.
+ $ jed Gemfile
+ - gem 'active_scaffold'
+ + gem 'active_scaffold', git: 'https://github.com/activescaffold/active_scaffold.git', branch: 'master', ref: 'b3a4859'
+ $ # https://github.com/activescaffold/active_scaffold#quick-start
+ $ bundle install
+ $ rails g active_scaffold:install
+ Running via Spring preloader in process 13454
+ route concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
+ route concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
+ insert app/assets/javascripts/application.js
+ insert app/assets/stylesheets/application.css
+ $ rails db:create
+ Created database 'db/development.sqlite3'
+ Created database 'db/test.sqlite3'
+
+** モデルの作成 [#t681bc7f]
+
+ $ rails g active_scaffold:resource Test name:string email:string
+ Running via Spring preloader in process 13486
+ invoke active_record
+ create db/migrate/20171110143107_create_tests.rb
+ create app/models/test.rb
+ invoke test_unit
+ create test/models/test_test.rb
+ create test/fixtures/tests.yml
+ route resources :tests, concerns: :active_scaffold
+ invoke active_scaffold:controller
+ create app/controllers/tests_controller.rb
+ create app/helpers/tests_helper.rb
+ invoke test_unit
+ create test/controllers/tests_controller_test.rb
+ create app/views/tests
+ $ rake db:migrate
+ == 20171110143107 CreateTests: migrating ======================================
+ -- create_table(:tests)
+ -> 0.0052s
+ == 20171110143107 CreateTests: migrated (0.0056s) =============================
+ $ git commit -a -m "active_scaffold を master ブランチの最新版にした"
+ $ rails s
+
+http://localhost:3000/tests
+
+へのアクセスで
+
+ uninitialized constant Jquery
+
+が出た。
+
+** jQuery のインストール [#c7402813]
+
+ LANG:console
+ $ jed Gemfile
+ + gem 'jquery-rails'
+ + gem 'jquery-ui-rails'
+ $ bundle install
+ $ git commit -a -m "gem jquery-rails, jquery-ui-rails added"
+ $ rails s
+
+これで一覧画面が出た。
+
+&ref(tpsf-tests-list1.png,,75%);
+
+** Create New でエラーが出る [#i673c95d]
+
+ Uncaught SyntaxError: Unexpected token <
+ at processResponse (rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:246)
+ at rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:173
+ at XMLHttpRequest.xhr.onreadystatechange (rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1:230)
+
+エラーが出たのは、
+
+ LANG:javascript
+ } else if (type.match(/\b(?:java|ecma)script\b/)) {
+ script = document.createElement('script');
+ script.text = response;
+ document.head.appendChild(script).parentNode.removeChild(script);
+
+appendChild の所なので、javascript を期待してたのに html が帰ってきてしまったという感じ。
+
+えー、そんなぁ。
+
+** javascript の require を直す [#be38a622]
+
+ LANG:console
+ $ jed app/assets/javascripts/application.js
+ - // require rails-ujs
+ + //# require rails-ujs
+ + //= require jquery
+ + //= require jquery_ujs
+ + //= require active_scaffold
+ $ git commit -a -m "active_scaffold が動くように application.js の require を修正"
+
+Create New が動くようになった。
+
+&ref(tpsf-tests-new1.png,,75%);
+
+** Paper Trail による履歴管理を追加 [#j4e8a399]
+
+ LANG:console
+ $ rails g paper_trail:install
+ Running via Spring preloader in process 14299
+ create db/migrate/20171110151301_create_versions.rb
+ create config/initializers/paper_trail.rb
+ $ rake db:migrate
+ == 20171110151301 CreateVersions: migrating ===================================
+ -- create_table(:versions)
+ -> 0.0074s
+ -- add_index(:versions, [:item_type, :item_id])
+ -> 0.0031s
+ == 20171110151301 CreateVersions: migrated (0.0112s) ==========================
+ $ jed app/models/test.rb
+ class Test < ApplicationRecord
+ + has_paper_trail :ignore => [:id, :created_at, :updated_at]
+ end
+ $ jed app/controllers/tests_controller.rb
+ class TestsController < ApplicationController
+ active_scaffold :"test" do |conf|
+ + conf.columns.exclude :versions
+ end
+ end
+ $ rails s
+
+app/models/test.rb
+ LANG:ruby
+ class Test < ApplicationRecord
+ + has_paper_trail :ignore => [:id, :created_at, :updated_at]
+ end
+
+app/controllers/tests_controller.rb
+ LANG:ruby
+ class TestsController < ApplicationController
+ active_scaffold :"test" do |conf|
+ + conf.columns.exclude :versions
+ end
+ end
+
+&ref(tpsf-list-listdeletedrecords.png,,75%);
+
+なぜだか List Deleted Records というリンクができてて、しかも押すとエラーになる。
+
+どうやら active_scaffold 自体に paper_trail への対応が含まれているらしく、
+ただ残念ながらバグっているっぽい。
+
+ Processing by TestsController#deleted as JS
+ Parameters: {"adapter"=>"_list_inline_adapter"}
+ Completed 500 Internal Server Error in 51ms (ActiveRecord: 1.4ms)
+
+
+
+ TypeError (can't cast Class):
+
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/quoting.rb:45:in `rescue in type_cast'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/quoting.rb:32:in `type_cast'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/quoting.rb:166:in `block in type_casted_binds'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/quoting.rb:166:in `map'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/quoting.rb:166:in `type_casted_binds'
+ activerecord (5.1.4) lib/active_record/connection_adapters/sqlite3_adapter.rb:206:in `exec_query'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:371:in `select'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/database_statements.rb:42:in `select_all'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `block in select_all'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/query_cache.rb:117:in `block in cache_sql'
+ /home/osamu/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/query_cache.rb:104:in `cache_sql'
+ activerecord (5.1.4) lib/active_record/connection_adapters/abstract/query_cache.rb:95:in `select_all'
+ activerecord (5.1.4) lib/active_record/relation/calculations.rb:253:in `execute_simple_calculation'
+ activerecord (5.1.4) lib/active_record/relation/calculations.rb:209:in `perform_calculation'
+ activerecord (5.1.4) lib/active_record/relation/calculations.rb:118:in `calculate'
+ activerecord (5.1.4) lib/active_record/relation/calculations.rb:41:in `count'
+ /home/osamu/.rvm/gems/ruby-2.4.2@album/bundler/gems/active_scaffold-b3a48596187f/lib/active_scaffold/bridges/paper_trail/actions.rb:15:in `deleted'
+
+ LANG:ruby
+ def deleted
+ query = PaperTrail::Version.destroys.where(:item_type => active_scaffold_config.model)
+ query = query.where_object(nested.child_association.foreign_key => nested.parent_id) if nested? && nested.child_association.belongs_to? && PaperTrail::Version.respond_to?(:where_$
+ > pager = Paginator.new(query.count, active_scaffold_config.list.per_page) do |offset, per_page|
+ query.offset(offset).limit(per_page).map(&:reify)
+ end
+ @pagination_action = :deleted
+ @page = pager.page(params[:page] || 1)
+ @records = @page.items
+ respond_to_action(:list)
+ end
+
+ここでは消去済みレコードは paranoia で管理する予定なので、
+リンクを消してしまうだけで良い?
+
+app/controllers/tests_controller.rb
+ LANG:ruby
+ class TestsController < ApplicationController
+ active_scaffold :"test" do |conf|
+ conf.actions.exclude :deleted_records
+ conf.columns.exclude :versions
+ end
+ end
+
+** モデルに履歴情報へのリンクを持たせる [#nefe1550]
+
+app/models/test.rb
+ LANG:ruby
+ class Test < ApplicationRecord
+ has_paper_trail
+ +
+ + class History < ItemHistory
+ + end
+ + has_many :histories, -> { where 'item_type = "Test"' }, foreign_key: 'item_id', class_name: 'Test::History'
+ end
+
+app/models/item_history.rb
+ LANG:ruby
+ + class ItemHistory < PaperTrail::Version
+ + def method_missing(action)
+ + unless self.reify.attributes.keys.index(action.to_s).nil?
+ + self.reify[action]
+ + else
+ + super
+ + end
+ + end
+ + end
+
+config/routes.rb
+ LANG:ruby
+ concern :active_scaffold_association, ActiveScaffold::Routing::Association.new
+ concern :active_scaffold, ActiveScaffold::Routing::Basic.new(association: true)
+ resources :tests, concerns: :active_scaffold
+ + resources :tests do
+ + as_routes
+ + resources :histories, controller: 'test/histories' do
+ + as_routes
+ + end
+ + end
+
+app/controllers/test/histories_controller.rb
+ LANG:ruby
+ + class Test::HistoriesController < ApplicationController
+ + active_scaffold :"test/history" do |conf|
+ + end
+ + end
+
+あれ、エラーが出るな
+
+
+
* 質問・コメント [#t616f744]
#article_kcaptcha