开发者

render :partial returning an array when defined in ApplicationController but string when in ApplicationHelper

This method:

  def admin_buttons
    render :partial => 'portable/admin/admin_buttons'
  end

returns this (not html_safe) when defined in ApplicationControler and made a helper with helper_method:

["my partial's output "]

B开发者_开发技巧ut it returns the expected string normally when defined in ApplicationHelper.

I don't understand. This is new behavior as far as I know in rails 3.1


Simply put, don't call the controller's render in helpers. It just does not work that way

render in the controller and render in a helper can't be used interchangeably. This isn't new in Rails 3.1.

When you call render in the controller it eventually does call render on the view, the result of which is stored as its response_body. The response body is eventually returned in the way Rack expects, as a string array (what you see as your output).

These links may shed some more light on how this works:
- The controller's definition of render (metal)
- It's superclass method, where response_body is set (abstract_controller)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜