posts_controller.rb
class PostsController < ApplicationController
def new
@post = Post.new
end
end
_form.html.erb
<%= form_with(model: post, local: true) do |form| %>
<div class="field">
<%= form.label :title %>
<%= form.text_field :title %>
</div>
<% end %>
Above is my code. Why is an instantiation of the class Post as @post in the controller can be accessed as a local variable in the view as post? Hoping I could get an answer from this concern.
new.html.erbview file. It should have a code construction similar torender partial: "form", locals: { post: @post }, which passes the local variable to the underlying view_form.html.erb. Take a look at this documentation for the more detailed explanation: guides.rubyonrails.org/…