-1

I have a header menu with my cart in it. I don't know where I must write my query and show the items in the cart.

My shared views is in /views/shared/_header.html.erb and I can't find any solution for sending variable to it.

Sneha
  • 2,200
  • 6
  • 22
  • 36

1 Answers1

1

Any action you request must query the items. Save the results and pass it to the view.

Try this:

 render "shared/header", variable: @variable

 Or

 render partial: "shared/header", locals: { variable: @variable }
Evan
  • 521
  • 4
  • 11
  • yes but where I must put the action? I mean in which controller. – Sarmad Rezayat Aug 08 '17 at 09:52
  • For example: If you render the partial in your home page, You must query the items in you home controller and index action. If you render the partial in your products show page, You must query the items in you products controller and show action. Simply. You can just use current_cart.items in the partial – Evan Aug 08 '17 at 10:00
  • It is in my sherd header view and load in all over my app – Sarmad Rezayat Aug 08 '17 at 10:36