views:

142

answers:

3

I use link_to_remote to pull the dynamic contents of a partial onto the page. It's basically a long row from a database of "todo's" for the day.

So as the person goes through and checks them off, I want to show the updated list with a line through those that are finished.

Currently, I end up needing to click on the link_to_remote again after an item is ticked off, but would like it to redirect back to the "cached" page of to-do's but with the one item lined through.

How do I do that?

Here is the main view:

<% @campaigns.each do |campaign| %>
<!--link_to_remote(name, options = {}, html_options = nil)-->

<tr><td>   <%= link_to_remote(campaign.name, :update => "campaign_todo",
        :url => {:action => "campaign_todo",
                 :id => campaign.id 
          }
       ) %>  </td></tr> 


<% end %>
</table>

<div id="campaign_todo">


</div>

I'd like when the New/Create actions are done to go back to the page that redirected it there.

When someone wants to "do" a task, it takes them to the new action. here is the controller:

  def create
    @contact_call = ContactCall.new(params[:contact_call])


    if @contact_call.save
      flash[:notice] = "Successfully created contact call."
      redirect_to contact_path(@contact_call.contact_id)
    else
      render :action => 'new'
    end
  end

I switched to redirect_to :back, which takes me back to the main view shown above...but WITHOUT the PARTIAL. It means I need to reload the partial all over again, which is a time-consuming database call.

1) Is it possible to go back to a view that has a partial called through AJAX and still have those results show up? 2) Can that result, however, be marked via CSS to indicate that it has been "checked off"?

A: 

you have to create an ajax call when you mark one item as 'done', in this action you'll need to

  1. update your list item to add the 'line-through' to text-decoration
  2. create a method like 'after_save', to expire your cache

you can read about the CSS 'line-through' here: http://www.icelab.eu/en/blog/css-4/xhtml-and-css-strike-alternatives-86.htm

and the documentation for expire_page and expire_action is here: http://api.rubyonrails.org/classes/ActionController/Caching/Sweeping.html

vrsmn
thanks...I think I need to update the question further....
Angela
A: 

I think you may be able to use action caching on your index action, or whatever the name of the action is that renders your main page.

You can also do page caching and fragment caching, which would work with partials. For more information on Rails caching strategies, see the rails guide: http://guides.rails.info/caching_with_rails.html

Mark Thomas
+1  A: 

I would render the to-do list item response from javascript ERB files. So when you make the link_to_remote call, instead of redirecting back to the page, instead render javascript.

You'd have the form in /app/views/contact_call/_form.html.erb

/app/views/contact_call/create.js.rjs

page.replace :contact_form, :partial => "contact_call/form", :locals => { :user => @user }
page.visual_effect :highlight, :contact_form

Your controller would then render the javascript, which would in turn replace html on your page with the latest version (and highlight it). And your page would load the partial with strike-through on completed items.

Jesse Wolgamott
would this work in an authenticated session page? it seems like it would....would this speed it up in terms of the call to the database?
Angela
Yep, nothing in it would prevent it from working in an unauthenticated setup. You may _want_ to restrict to authenticated users in a to-do list thing, but that's up to you.
Jesse Wolgamott