Let's say I have a controller with 2 collection actions for viewing tasks 
(accessed by /tasks/active and tasks/complete respectively).

  def active
    @tasks = Task.all(:complete => false)
    respond_with(@tasks)
  end
  
  def complete
    @tasks = Task.all(:complete => true)
    respond_with(@tasks)
  end

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:

  def create
    @task = Task.new(params[:task])
    @task.save
    respond_with(@task, :location => tasks_path) do |format|
      format.js # reload task list
    end
  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.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/rubyonrails-talk/-/WGTUB2sKO10J.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to