Let’s say I have a controller with 2 collection actions for viewing tasks (accessed by /tasks/active and tasks/complete respectively).
@tasks = Task.all(:complete => false) respond_with(@tasks)
@tasks = Task.all(:complete => true) respond_with(@tasks)
The views for both of these actions have a form for creating a new task which submits via ajax. The view looks something like the following:
@task = Task.new(params[:task]) @task.save respond_with(@task, :location => tasks_path) do |format| format.js # reload task list end
My question is about the “reload task list” line. When the task is created, I need to reload the task list. If the task was created from the “completed” page, we would want to reload the “completed” data set, and if it was created from the “active” page we would want to reload the “active” data set.
What’s the most DRY way to detect which page the task was created from and reload the appropriate data set?
I could check whether “/active” or “/complete” is in the HTTP referrer, but that feels kind of hack-ish.