質問編集履歴

2

ApplicationController.rb追加

2020/06/14 01:16

投稿

HTMLdoc
HTMLdoc

スコア67

test CHANGED
File without changes
test CHANGED
@@ -472,7 +472,7 @@
472
472
 
473
473
  ```
474
474
 
475
-
475
+ application.controller.rb
476
476
 
477
477
  ```ruby
478
478
 

1

ApplicationController.rb追加

2020/06/14 01:16

投稿

HTMLdoc
HTMLdoc

スコア67

test CHANGED
File without changes
test CHANGED
@@ -471,3 +471,53 @@
471
471
  </script>
472
472
 
473
473
  ```
474
+
475
+
476
+
477
+ ```ruby
478
+
479
+ class ApplicationController < ActionController::Base
480
+
481
+ protect_from_forgery
482
+
483
+ # ApplicationController.render 'messages/message'
484
+
485
+ before_action :configure_permitted_parameters, if: :devise_controller?
486
+
487
+ before_action :search
488
+
489
+ def configure_permitted_parameters
490
+
491
+ devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
492
+
493
+ end
494
+
495
+
496
+
497
+ def self.render_with_signed_in_user(user, *args)
498
+
499
+ ActionController::Renderer::RACK_KEY_TRANSLATION['warden'] ||= 'warden'
500
+
501
+ proxy = Warden::Proxy.new({}, Warden::Manager.new({})).tap{|i| i.set_user(user, scope: :user) }
502
+
503
+ renderer = self.renderer.new('warden' => proxy)
504
+
505
+ renderer.render(*args)
506
+
507
+ end
508
+
509
+
510
+
511
+ def search
512
+
513
+ @q = Room.ransack(params[:q])
514
+
515
+ @rooms = @q.result(distinct: true).where(public: true)
516
+
517
+ end
518
+
519
+ end
520
+
521
+
522
+
523
+ ```