Jean N. wrote:
Hi
Actually, aside from having empty_cart.rjs and NOT _empty_cart.rjs (as
none of my rjs templates require the starting _, only my partials do) I
still am not able to call another method and then render the
empty_cart.rjs. It seems that every time the remove_from_cart.rjs is the
final render even with [render :file => “empty_cart” or
“empty_cart.rjs”] after the method call.
I’ll post some more code in a bit once I can get access to my home
machine.
Thanks.
Synopsis of Issue: (many replies make it hard to follow the current
state of my app)
The ‘empty_cart’ action works perfects if button/link clicked from the
site. Calling ‘remove_from_cart’ works perfectly EXCEPT when the item
being removed is the LAST item in the cart. When that happens I want to
(redirect?) the call to remove_from_cart to the empty_cart action and
then have the associated empty_cart.rjs template rendered, NOT the one
that Rails would render [by default] “remove_from_cart.rjs”.
Here’s some code I have (snipped in places for brevity).
controller / rjs code
THE CONTROLLER
def remove_from_cart
@cart = find_cart
begin
product = Product.find( params[:id])
rescue ActiveRecord::RecordNotFound
logger.error( “Attempt to access invalid product #{params[:id]}”)
redirect_to_index( “Invalid product to remove.” )
else
@current_item = @cart.remove_product(product)
end
#-- Where the magic should happen!
if @cart.items.size <= 0
empty_cart
render :partial => "empty_cart"
end
end
def empty_cart
session[:cart] = nil
end
THE RJS TEMPLATES: remove_from_cart.rjs
page.replace_html( “cart”, :partial => “cart”, :object => @cart )
page[:cart].visual_effect :shake
THE RJS TEMPLATES: empty_cart.rjs
page[:cart].visual_effect :puff
<<<<<<<<<< end controller / rjs code
Log file Error:
ActionView::ActionViewError (No rhtml, rxml, rjs or delegate template
found for store/_empty_cart in
/home/jbateman/sandbox/depot/config/…/app/views):
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:399:in
find_template_extension_for' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:335:in
pick_template_extension’
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:249:in
render_file' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_view/base.rb:275:in
render’
I ‘feel’ I have researched this well and have a good understanding of
the flow of events ‘behind the scenes’ (Thanks mostly to all of you who
have replied to me) but I’m still missing something that is not
‘clicking’ in my head on how to do this.
Thanks!