Why to use _form.html.erb in rails

ruby, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.2

Solution

File Starts with "_" underscore called partials in rails. It encourages DRY(Do not repeat yourself) principle of software developement. You can reuse partials and in this case _form.html.erb can be used for both new.html.erb and edit.html.erb functionality. We can render partials in other html.erb files or called within the controllers too. `render :partial => 'partial_name'` without underscore in the partial_name.

Problem

I am new to Ruby on Rails.I was using scaffold to create models views and controllers for `admin` Now one of my seniors has told me to make changes in `_form.html.erb` for admin.I have no idea how to implement it.Also what is the advantage or disadvantage of using/making changes in _form.html.erb as compared to normal method(make changes in index,new,show and edit) My _form.html.erb is as follows:- ``` <%= form_for(@admin) do |f| %> <% if @admin.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@admin.errors.count, "error") %> prohibited this admin from being saved:</h2> <ul> <% @admin.errors.full_messages.each do |msg| %> <li><%= msg %></li> <% end %> </ul> </div> <% end %> <div class="actions"> <%= f.submit %> </div> <% end %> ``` My Admin table is as follows:- ``` id serial NOT NULL, username character varying(20) NOT NULL DEFAULT ''::character varying, email character varying(255), first_name character varying(100), middle_name character varying(100), last_name character varying(100), designation character varying(255), office_phone character varying(255), deleted integer NOT NULL DEFAULT 0, super_admin boolean NOT NULL DEFAULT false, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, CONSTRAINT admins_pkey PRIMARY KEY (id) ``` Can someone help me implement this.Thanks in advance

Original source