Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>How long are you programming with ruby? You have to create a new instance of your class to access the instance outside. Take a look at these basics: <a href="http://www.tutorialspoint.com/ruby/ruby_variables.htm" rel="nofollow">http://www.tutorialspoint.com/ruby/ruby_variables.htm</a></p> <p><strong>UPDATE</strong></p> <p>From the link above..</p> <p>Ruby Instance Variables:</p> <p>Instance variables begin with @. Uninitialized instance variables have the value nil and produce warnings with the -w option.</p> <p>Here is an example showing usage of Instance Variables.</p> <pre><code>class Customer def initialize(id, name, addr) @cust_id=id @cust_name=name @cust_addr=addr end def display_details() puts "Customer id #@cust_id" puts "Customer name #@cust_name" puts "Customer address #@cust_addr" end end # Create Objects cust1=Customer.new("1", "John", "Wisdom Apartments, Ludhiya") cust2=Customer.new("2", "Poul", "New Empire road, Khandala") # Call Methods cust1.display_details() cust2.display_details() </code></pre> <p>That´s how you can work with ruby and instance variables. More details are in the link.</p> <p>In your case I think you have another "error", you mixed a few things.. where is your helper class? Under the app/helpers/store_helper.rb? In this file you should just add view helpers. If I am right with my intuitions I would solve your problem like following:</p> <p>app/helpers/store_helper.rb</p> <pre><code>module StoreHelper def get_level_states(product) product_sales = product.line_items.total_product_sale.sum("quantity") product.volume2 = 0 if product.volume2.nil? product.volume3 = 0 if product.volume3.nil? levels = {} if (product_sales &gt;= product.volume2) &amp;&amp; (product_sales &lt; product.volume3) levels[:1] = "On!" levels[:2] = "On!" levels[:3] = "Active!" elsif product_sales &gt;= product.volume3 levels[:1] = "On!" levels[:2] = "On!" levels[:3] = "On!" else levels[:3] = "Pending" end levels end end </code></pre> <p>app/views/your_views_folder/your_view.html.erb</p> <p>to get the different level state:</p> <pre><code>&lt;% levels = get_level_states(product) %&gt; &lt;%= levels[:1] %&gt; # will print the level 1 &lt;%= levels[:2] %&gt; # will print the level 2 &lt;%= levels[:3] %&gt; # will print the level 3 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload