 <p>Let's try to understand this whole process point-wise</p> <p><strong>Instance variables defined in the controller action are shared with the rendered views.</strong></p> <p>In your case I'm assuming that there's a <code>new</code> action something like</p> <pre><code>def new @movie = Movie.new end </code></pre> <p>And you have a corresponding view <code>new.html.erb</code> where you have created a form like this</p> <pre><code>= form_for @movie do |f| </code></pre> <p>Now, as you know the <code>@movie</code> object that you are passing in <code>form_for</code> method is defined in <code>new</code> action. Most of the times we don't pass any parameters to the <code>new</code> method in <code>new</code> action. The form fields are blank when you load the form because the attributes of the object(in your case <code>@movie</code>) are by default blank because we just initialize an empty object(<code>Movie.new</code>). </p> <p>Let's assume your <code>Movie</code> model has a <code>name</code> attribute, Try doing this in your <code>new</code> action</p> <pre><code>def new @movie = Movie.new(name: 'Hello World!') end </code></pre> <p>Now when you will load the new action, you will see <code>Hello World!</code> populated in your <code>name</code> text field because your <code>@movie</code> object is initialized with this value. </p> <p>Also, keep in mind that Rails Convention-Over-Configuration automatically generates the form URL in this case, by default it points to the <code>create</code> action. When you submit the <code>form</code> the request is made to the create action. This takes me to the next point.</p> <p><strong>When we submit the form all the filled in form values are sent to the action whose route matches with the form URL(in your case URL points to the <code>create</code> action)</strong></p> <p>In <code>create</code> action you are receiving parameters in the form of a hash with model attributes(<code>Movie</code> attributes) as keys and the filled in information as their values. The first line in your <code>create</code> action is</p> <pre><code>@movie = Movie.new(movie_params) </code></pre> <p>This is a very important line of code, try to understand this. Let's assume your form had only one text field, i.e., <code>name</code>. Now <code>movie_params</code> is a method that looks like this</p> <pre><code>def movie_params params.require(:movie).permit(:name) end </code></pre> <p>Now, the <code>movie_params</code> method will return a hash something like <code>{ 'name' =&gt; 'Hello World!' }</code>, now you are passing this hash as a parameter to <code>Movie.new</code> method.</p> <p>So now, after breaking up the code, the first line of your create action looks like</p> <pre><code>@movie = Movie.new({ name: 'Hello World!' }) </code></pre> <p>That means your <code>@movie</code> instance variable contains an object of <code>Movie</code> class with <code>name</code> attribute set to <code>Hello World!</code>. Here, when after initialization, if you do <code>@movie.name</code> it will return <code>Hello World!</code>.</p> <p>Now, in the second line you are calling <code>@movie.save</code> that returned <code>false</code> due to failed validation in your case as you have already mentioned in the question. As it returned <code>false</code> the execution will go to the <code>else</code> part. Now this takes me to the next point.</p> <p><strong>Calling <code>render :action</code>(in your case <code>render :new</code>) in the controller renders only the view that belongs to that action and does not execute that action code.</strong></p> <p>In your case, you called <code>render :new</code>, so there you are actually rendering the <code>new.html.erb</code> view in create action. In other words, you are just using the code in <code>new.html.erb</code> and not in <code>new</code> action. Here, <code>render :new</code> does not actually invoke the new action, it's still in the create action but rendering the <code>new.html.erb</code> view.</p> <p>Now, in <code>new.html.erb</code> you have created a form that looks like</p> <pre><code>= form_for @movie do |f| </code></pre> <p>Now as my explained under my first point, the instance variables that are declared in the action are shared by the rendered view, in this case <code>@movie</code> object that you have defined in <code>create</code> action is shared by the rendered <code>new.html.erb</code> in create action. In our case, in <code>create</code> action the <code>@movie</code> object was initialized with some values that were received in the parameters(<code>movie_params</code>), now when <code>new.html.erb</code> is rendered in the <code>else</code>, the same <code>@movie</code> object is used in the form by default. You got the point right, you see the magic here?</p> <p>This is how Rails works and that's why its awesome when we follow the convention! :)</p> <p>These blogs will help you understand the code better,</p> <p><a href="http://blog.markusproject.org/?p=3313" rel="nofollow noreferrer">http://blog.markusproject.org/?p=3313</a></p> <p>And this gist is great,</p> <p><a href="https://gist.github.com/jcasimir/1210155" rel="nofollow noreferrer">https://gist.github.com/jcasimir/1210155</a></p> <p>And last but not least, the official Rails Guides on Layouts and Rendering</p> <p><a href="http://guides.rubyonrails.org/v4.2/layouts_and_rendering.html" rel="nofollow noreferrer">http://guides.rubyonrails.org/v4.2/layouts_and_rendering.html</a></p> <p>Hope the above examples cleared your doubts, if not, feel free to drop your queries in the comment box below. :) </p>