E
E
eldar_web2015-06-05 17:59:02
Ruby on Rails
eldar_web, 2015-06-05 17:59:02

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

2 answer(s)
E
eldar_web, 2015-06-05
@eldar_web

It is transmitted like this:<%= render :new, object: @new_customer %>

V
Viktor Vsk, 2015-06-05
@viktorvsk

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 question

Ask a Question

731 491 924 answers to any question