开发者

Subclass of AbstractController requires explicit render call

I am trying to figure out how to render views from models in the best way. The best approach that I have f开发者_如何学Cound so far is to extend AbstactController because then I can structure the code as MVC. Now, only a slight issue remains: I have to call render explicitly in my action methods to render the view (which is not needed in Rails).

For example: to create an alternative to ActionMailer I implemented an EmailsController class which extends AbstractController.

class EmailsController < AbstractController::Base
  include AbstractController::Rendering
  include AbstractController::Layouts
  include AbstractController::Helpers
  include AbstractController::Translation
  include AbstractController::AssetPaths
  include ActionController::UrlWriter

  helper ApplicationHelper

  self.view_paths = "app/views"

  def notification
    render 'notification'
  end
end

How can I get rid of the render call?

Thanks!


You need to also include include ActionController::ImplicitRender. It renders default view if response body was not rendered yet: https://github.com/rails/rails/blob/5b2eb64ceb08cd005dc06b721935de5853971473/actionpack/lib/action_controller/metal/implicit_render.rb#L5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜