0

I have an app where a product can have a regular price or a discounted price both of which are saved in two seperate columns in my database as: price and offer.

I have a controller called 'generals' which is for all general products.

What I would like to happen is that if 'general.offer' is blank then the div that wraps the price will have a class of 'product-price'. If however there is a value present in general.offer then the div will have a class of 'product-special-price'.

Currently I have the following:

#View

<div class="<%= product_price %>">
  <%= general.price %>
</div> 


#Application Helper

def product_price
   if general.offer.blank?
      return "product-price"
   else
      return "product-special-price"
   end
end

At the moment I am receiving a wrong number of arguments error. Any advice people have on how to fix this would be much appreciated :)

1
  • Hi Michael, Sorry the error I am receiving is undefined local variable or method general for #<#<Class:0x61fc908>:0x5dce1d8>. Thanks so much for your help! Commented Jul 22, 2013 at 14:13

1 Answer 1

1

I think you should pass general to product_price but depends on the error you're getting.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Michael, How would I pass general into product_price. Would it be using @general defined in my generals controller ie. @general.offer.blank? When doing this I am left with error undefined method offer for nil:NilClass
There's no magic in Rails! You need to pass it explicitly product_price(general), both in declaration and when you call it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.