Railsでapp/controllers/concernsを使ってみた
コントローラーに記入するコードが長くなってしまった為、メソッドをまとめて別の場所に書きたいなと思ったので、今回concernsを使ってみました。
最初は下記の様にすべてをコントローラーに書いていて見にくくなってきたので
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base def index arr = get_arr end end def get_arr [1,2,3] end
このように書き換えました
app/controllers/application_controller.rb
class ApplicationController < ActionController::Base def index arr = ArrFunc.get_arr end end
app/controllers/concerns/arr_func.rb
module ArrFunc def self.get_arr [1,2,3] end end