Forum: Ruby on Rails saving controller state

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
opensas (Guest)
on 2006-04-11 09:57
Basically I'm trying to add the following functionality to a controller
when browsng data

reorder data
change numbers of rows
defining filters
etc.

for that, I need to save the state of a controller, that is, the current
order, the number of rows, the filter condition, etc.

So far now, I'm saving them to the session.

I have a load method, which loads the data from params, or assing
default values.

Something like this

def load
  @order = session[:order] || 'date desc'
  @order = params[:order] if params[:order]
end

And then I have another method to save the data

def save
  session[:order] = @order
end

The problem is that for every method I have to execute "load" do some
stuff and then execute "save"

like this

def list
  load
  @resolucion_pages, @resoluciones = paginate :resolucion, :order =>
@order, :per_page => 10
  save
end

Is there some way to automatize this?

I tried with the initialize method, but it seems like the session is not
available on that method.

Saludos

Sas
Mikkel B. (Guest)
on 2006-04-11 11:16
(Received via mailing list)
you could use a before and after filter...


On Tuesday, April 11, 2006, at 7:57 AM, opensas wrote:
>
>end
>like this
>I tried with the initialize method, but it seems like the session is not
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails


Mikkel B.

www.strongside.dk    - Football Portal(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
Sas S. (Guest)
on 2006-04-11 12:30
Mikkel B. wrote:
> you could use a before and after filter...
>

Thanks a lot Mikkel, that's exactly what I was looking for.

Saludos

Sas
This topic is locked and can not be replied to.