LoginSignup
2
2

More than 5 years have passed since last update.

Ruby - LotusのControllerをRailsっぽく1ファイルにまとめたい

Last updated at Posted at 2015-04-20

routingの設定で少し悩んだのでメモ

# apps/web/config/routes.rb
get '/', to: 'home#index'
get '/show', to: 'home#show'

このようにroutingに記述した場合、1画面ごとに対応するファイルを作った。
個人的に、これファイル多すぎと感じたので下記のように記述したところ動作した。

before

  • apps/web/controllers/home/index.rb
module Web::Controllers::Home
  class Index
    include Web::Action

    def call(params)
    end
  end
end
  • apps/web/controllers/home/show.rb
module Web::Controllers::Home
  class Show
    include Web::Action

    def call(params)
    end
  end
end
  • apps/web/views/home/index.rb
module Web::Views::Home
  class Index
    include Web::View
  end
end
  • apps/web/views/home/show.rb
module Web::Views::Home
  class Show
    include Web::View
  end
end
  • apps/web/templates/home/index.html.erb
  • apps/web/templates/home/show.html.erb

after

  • apps/web/controllers/home/index.rb
module Web::Controllers::Home
  class Index
    include Web::Action

    def call(params)
    end
  end

  class Show
    include Web::Action

    def call(params)
    end
  end
end
  • apps/web/views/home/index.rb
module Web::Views::Home
  class Index
    include Web::View
  end

  class Show
    include Web::View
  end
end 
  • apps/web/templates/home/index.html.erb
  • apps/web/templates/home/show.html.erb

あんましっくりきてないけどとりあえずはこれで行こうと思う。
もっといい書き方あったら教えてください。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2