0

I have a tiny but silly problem over here, i have a model action;

def self.price_change_up(network, currency, change )
    prices = Prices.where('network = ?', network) 
    prices.each do |price|
      price.send("#{currency}") = price.send("#{currency}") + change
      price.save
    end
  end

but the line

price.send("#{currency}") = price.send("#{currency}") + change

return a syntax error. What could be the problem.

3
  • Please provide your stacktrace... Commented Feb 9, 2014 at 9:43
  • your controller action cannot start with self as you posted here Commented Feb 9, 2014 at 10:07
  • @GhostRider, i have made an edit, it was model action Commented Feb 9, 2014 at 10:15

2 Answers 2

1

I suppose you want to do this instead:

price = price.send("#{currency}") + change

Your current example is invalid syntax because you are trying to assign something to a value, the return value of price.send("#{currency}") whatever may that be.

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

Comments

1

price.send("#{currency}") = price.send("#{currency}") + change

This is invalid, you can't use '=' to assign ,In case you are looking to use send with setter

 self.send("#{currency}=", prev_curr_value)

In the LHS, you are using price.send("#{currency}"), it calls a method dynamically and will return a value which is again being assigned to same value with some addition change which looks wierd. what are you trying to achieve here, explain with an updated qsn.

1 Comment

price.send("#{currency}=", price.send(currency) + change)

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.