Answer the question
In order to leave comments, you need to log in
How to pass a variable to view on render in Rails?
Let's say we passed some variable to the create page. And this variable is used in this page. And in the process of adding, during validation, the operation is not successful, and a redirect occurs in the controller, here is an example code: format.html { render :new }
And an error occurs in the page due to the fact that that variable does not exist, and it is valid when rendering if the operation is not successful (as in the code) nothing is transmitted. But how can you convey?
Answer the question
In order to leave comments, you need to log in
It is transmitted like this:<%= render :new, object: @new_customer %>
Less b "I".
And be clearer about your desires.
A render does not equal a redirect.
You can't redirect in the controller to fix validation errors.
In a controller action, it doesn't matter what you render and under what conditions. In any case, all instance variables will be available.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question