On Tuesday, February 18, 2014 10:56:13 AM UTC, MatCouto wrote:

> Hey folks,
> I was wondering what would be the best approach for this situation.
> In my application layout I've got a partial which shows the user's cart if 
> there is any. 
>
>>
>>
>> *- if @cart && [email protected]_items.empty?  %h1 Your Cart  = render @cart*
>
>  
> However, if I want to, for instance, click on the button to show me this 
> particular product details (/product/22), a NilException is thrown as I 
> would've lost @cart object on the request.
> I managed to fix it by adding this piece of code to the product's 
> controller:
>
> *before_action :load_current_cart, only: [:show]*
>
>  
>
>>
>> *def load_current_cart*
>> *  @cart = current_cart**end*
>
>
>  

> Is there a better/clean way to do it?
> Thanks in advance
>

I've been using http://cells.rubyforge.org for this sort of stuff - keeps 
that sort of data thing where closer to the thing that actually uses it 
rather than it being scattered across all the controllers that might need 
it.

Fred 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6d9e1c73-9533-4c32-a8b2-a6ee16d09d04%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to