Newbie: Corrcet use of Render :Partial for forms in CRUD?

Cna anyone point e at any rails 2.0 tutorials on simple use of partials
for forms in new and update CRUD operations?

Ive got the following new.html.erb and _user.html.erb partial

First the contents of new.html.erb

New user

<%= error_messages_for :user %>

<% form_for(@user) do |f| %>

<%= render :partial => @user %>

<%= f.submit "Create" %>

<% end %>

<%= link_to ‘Back’, users_path %>

…and the form partial…


<%= f.text_field :ImageName" %>

<%= f.text_field :SurName" %>

<%= f.text_field :ForeName" %>

<%= f.text_field :Title" %>

Room No
<%= f.text_field :RoomNo" %>

Phone No
<%= f.text_field :PhoneNo" %>

Position / Group
<%= f.text_field :Position_Group" %>

<%= f.text_field :Duties" %>

<%= f.text_field :EMail" %>

Hi Dale, I’m new to this too… for general reference, this may be
useful: Flashcards, notes and learning tools online: there’s info on
rails and a tool to help you learn rails. Best, Elizabeth

On Jun 3, 6:31 am, Dale C. [email protected]

Dale C. wrote:

Cna anyone point e at any rails 2.0 tutorials on simple use of partials
for forms in new and update CRUD operations?

At a basic level, you can think of a partial as a Lego building block…
from which you create your web form. You can have any number of
partials, each of which presents a different piece of your final

I use partials for all sorts of things on a web form - menus, content,
navigation links, etc.

Let’s say, from your example, that you want the new action for some
model to show ALL the attributes of the model, but you want the edit
action to only show a subset of the model attributes. If you put the
code related to the attributes common to those actions (new and edit)
into a partial, the new.html.erb can show the fields it needs to show
AND render the partial while the edit.html.erb would just render the

The value of partials really comes weighing the reusability of a chunk
of code and the cost to execute that hunk of code…

Would we put something into a partial that’s used only one place?
Probably not.

But, if your app shows, for instance, an address on multiple different
forms, you can create a partial that renders an address, and all the
places that need to show an address can employ that same partial. Less
code for you to maintain, and an enforced consistency within your
application - all addresses render the same. If it’s a duck, it should
look like a duck.

The next extension to that idea, at least for me, was to only render
something again (invoke the partial) if it changed since the last time
it was rendered. This gets into caching and cache sweepers. I put most
“slow moving” data (data that changes infrequently) into a partial that
I can cache - the left-nav menus available for a specific user, for
instance. Unless the admin changes permissions for a user, the menu that
user sees won’t change, and my app doesn’t have to regen the menus all
the time (fits my “slow moving” data rule).

If the list of models related to a given project (another of my models)
hasn’t changed, don’t re-render the partial that creates hyperlinks to
all those related models - which can be a lot of work - but show the
cached version of that partial (fits my “expensive to do” rule).

Divorcing that

So is this not working for you? The only thing I might want to add is
to pass the form helper object ‘f’ to the partial in the :locals hash.
Not sure if that’s necessary…

Ar Chron wrote:

Divorcing that

just ignore that incomplete thought… :frowning: