ApplicationController vs Helpers

Can anybody please explain to me, what kind of methods, except
before_filters, are appropriate for ApplicationController, and why not
to put them into some helper?

I have read an interesting blog post about helpers

where it is explained that the ApplicationHelper is not a good place to
keep the code, but what about ApplicationController?

Alexey.

On Aug 29, 2011, at 2:20 PM, Alexey M. wrote:

Alexey.

It’s not a hard-and-fast rule, but I’ve always heard that anything
that generates HTML belongs in a helper, and anything that marshalls
model instances belongs in a controller.

Walter

Thanks, but what about, say rendering xml with a template?
Or, a better question, is there an example of a method that should go
into ApplicationController and not into a specific controller or a
helper?

Alexey.

On Aug 29, 2011, at 2:51 PM, Alexey M. wrote:

Thanks, but what about, say rendering xml with a template?

Controller, in a respond_to block.

Or, a better question, is there an example of a method that should go
into ApplicationController and not into a specific controller or a
helper?

Authentication?

Walter

Walter D. wrote in post #1019090:

On Aug 29, 2011, at 2:51 PM, Alexey M. wrote:

Thanks, but what about, say rendering xml with a template?

Controller, in a respond_to block.

What if this is a big repeating block of code?

Or, a better question, is there an example of a method that should go
into ApplicationController and not into a specific controller or a
helper?

Authentication?

I use SessionsController and SessionsHelper for this.

Is ApplicationController a good place for anything other than
before_filter’s?

Alexey.

On Aug 30, 2011, at 4:32 AM, Alexey M. wrote:

Walter D. wrote in post #1019090:

On Aug 29, 2011, at 2:51 PM, Alexey M. wrote:

Thanks, but what about, say rendering xml with a template?

Controller, in a respond_to block.

What if this is a big repeating block of code?

I am not sure what you mean here. Are you talking about a template
actually being in your controller? Can you show an example (maybe cut
down) to show what you mean by a big repeating block?

Is ApplicationController a good place for anything other than
before_filter’s?

Looking at a couple projects I have open, mine are largely empty, with
a single method rescue_from_CanCan::AccessDenied and in one a method
called current_practice_id that just looks up the Devise current_user
and extracts that user’s practice id. Not much else going on here in
that file. I’m sure there are other great reasons to use it.

Walter

Walter D. wrote in post #1019206:

What if this is a big repeating block of code?

I am not sure what you mean here. Are you talking about a template
actually being in your controller? Can you show an example (maybe cut
down) to show what you mean by a big repeating block?

def render_ms_excel_2003_xml_for_download(scoped_collection,
                                          attributes,
                                          column_headers,
                                          filename=nil)
  klass = scoped_collection.klass
  if klass.superclass == AbstractSmarterModel
    column_types = klass.attribute_db_types
  else
    column_types = {}
    attributes.each do |attr|
      column_types[attr] = klass.columns_hash[attr.to_s].type
    end
  end
  filename ||= "#{klass.model_name.human.pluralize}"\
               " #{Time.now.in_time_zone.strftime('%Y-%m-%d 

%k_%M’)}"
“.excel2003.xml”
send_data render_to_string(
:template => ‘shared/index’,
:locals =>
{ :models => scoped_collection,
:attributes => attributes,
:column_types => column_types,
:column_headers => column_headers}),
:filename => filename,
:content_type => "#{Mime::MS_EXCEL_2003_XML.to_s}; "
“charset=utf-8”,
:disposition => ‘inline’
end

I use render together with send_data here only because i’ve found no
way to specify the default file name with render.

Is ApplicationController a good place for anything other than
before_filter’s?

Looking at a couple projects I have open, mine are largely empty, with
a single method rescue_from_CanCan::AccessDenied and in one a method
called current_practice_id that just looks up the Devise current_user
and extracts that user’s practice id. Not much else going on here in
that file. I’m sure there are other great reasons to use it.

Thanks for an opinion.

Alexey.