Suggestion: render filters

153 views
Skip to first unread message

Alexander Kurakin

unread,
Sep 5, 2012, 2:53:50 PM9/5/12
to rubyonra...@googlegroups.com
Will not be useful functionality similar https://github.com/shell/rails3_before_render ? Something like ActionController filters but not before action. Filters before render. See also http://www.perfectline.ee/blog/ruby-on-rails-before-render-filter, http://penkin.co.uk/rails3_before_render-plugin/. And don't you know gem for this? Thanks.

Carlos Antonio da Silva

unread,
Sep 7, 2012, 2:57:50 PM9/7/12
to rubyonra...@googlegroups.com
Please show any real use case where this will be useful, to make things more clear. Otherwise it's just hard to figure it out examples where it's useful or not. Thanks.

On Wed, Sep 5, 2012 at 3:53 PM, Alexander Kurakin <kura...@mail.ru> wrote:
Will not be useful functionality similar https://github.com/shell/rails3_before_render ? Something like ActionController filters but not before action. Filters before render. See also http://www.perfectline.ee/blog/ruby-on-rails-before-render-filter, http://penkin.co.uk/rails3_before_render-plugin/. And don't you know gem for this? Thanks.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/VVF2HksqidUJ.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-co...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.



--
At.
Carlos Antonio

Alexander Kurakin

unread,
Oct 17, 2012, 3:22:38 PM10/17/12
to rubyonra...@googlegroups.com
I think that links' authors know better than me all of causes. But I use render filters for decorating objects (similar to https://github.com/ohwillie/decorates_before_rendering) and setting page variables (that procedure is equal for each controller and use result of action's action).

P.S. It will be simply to realize with accepting suggestion https://groups.google.com/forum/?fromgroups#!topic/rubyonrails-core/uotv0zVISRE .

среда, 5 сентября 2012 г., 22:53:50 UTC+4 пользователь Alexander Kurakin написал:

Ryan Bigg

unread,
Oct 17, 2012, 3:27:45 PM10/17/12
to rubyonra...@googlegroups.com
This explanation seems almost schizophrenic.

What are you trying to say? Could you slow down and explain it in more elaborate terms please?

 
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/LpTEwnRYIEUJ.

Nick Sutterer

unread,
Oct 18, 2012, 10:26:17 AM10/18/12
to rubyonra...@googlegroups.com


On Wednesday, September 5, 2012 3:53:50 PM UTC-3, Alexander Kurakin wrote:
Will not be useful functionality similar https://github.com/shell/rails3_before_render ? Something like ActionController filters but not before action. Filters before render. See also http://www.perfectline.ee/blog/ruby-on-rails-before-render-filter, http://penkin.co.uk/rails3_before_render-plugin/. And don't you know gem for this? Thanks.

I guess he wants some mechanism that hooks into the action processing workflow so you can declarativly define stuff (in the controller, like a filter) that is done with the model before it is passed to the rendering layer. Just guessing without following the links!

Benjamin B

unread,
Jun 17, 2015, 6:57:14 AM6/17/15
to rubyonra...@googlegroups.com
Hi,

Reviving an old topic about the need of a before_render filter (topic found through Google, my apologies if there is a more recent thread)

Here is a use case:
- A controller's parent class is preparing a set of JavaScript variables to be passed to the view
- The view template is inserting those JavaScript variables in the HTML code
- The JavaScript variables need elements loaded/set by the controller

As the controller action takes place after the action filters and before the rendering, the only actual solution is to patch `render`.

Code example:
class ApplicationController

 
def render(*args)
   
unless @we_already_prepared_js_vars
     
@we_already_prepared_js_vars = true # This is to avoid loading those variable for each call of render
     
@_js_vars = prepare_js_vars
   
end

   
super
 
end
end

class UserController < ApplicationController
  before_filter :load_user

  def
prepare_js_vars
    {record_created_at: @user.created_at}
  end

  def
load_user
    @user = User.find params[:id]
  end
end

Would be more elegant to use a before_render filter in the ApplicationController

Regards

Ernie Miller

unread,
Jun 17, 2015, 7:01:40 AM6/17/15
to rubyonra...@googlegroups.com, ran...@gmail.com
Hi Benjamin,

This isn't really a valid use case. The way most of us would tackle something like this is to write a helper that lazy-loads the value in question, and call this from the view. This helper can exist in the controller class, if it needs access to your controller methods, and be made available to the view with the helper_method macro.

-Ernie

Benjamin Bouchet

unread,
Jun 17, 2015, 7:06:04 AM6/17/15
to rubyonra...@googlegroups.com
Hi Emie,

Thanks for the quick answer. 
This is actually what I was implementing while searching for an alternate solution, your answer confirm I’m on the right track.

Regards,
Benjamin

You received this message because you are subscribed to a topic in the Google Groups "Ruby on Rails: Core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rubyonrails-core/ockZdwf00VM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rubyonrails-co...@googlegroups.com.

To post to this group, send email to rubyonra...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages