0

I have a Portfolio scaffold. From the update method of the controller, I am calling the show view. However, a variable (@weights) that I am instantiating in the controller does not preserve its value.

Controller:

@weights = @portfolio.compute_weights
pp "in the controller, the weights are #{@weights}"
format.html { redirect_to @portfolio, notice: 'Portfolio was successfully updated.' }
format.json { render :show, status: :ok, location: @portfolio }

View

<% pp "in the view, the weights are #{@weights}"%>

The output is

"in the controller, the weights are {\"Bitcoin\"=>1.0, \"Litecoin\"=>0.0}"
"in the view, the weights are "

Why is this happening?

1
  • Put this in your view file <%= debug @weights%> and let me know what you are getting Commented May 25, 2015 at 14:28

2 Answers 2

1

You are redirecting to a different controller when in format.html block.

All the initialized variables are lost, if we redirect to another controller method.

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

2 Comments

Is there any way of storing a hash for every record?
can you ask it as a different question??
0

Change pp to = and try like this,

<%= "in the view, the weights are #{@weights}"%>

Comments

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.