Partials Question

I have a partial called _profile.html:

Name
<%= f.text_field :name %>

Email
<%= f.text_field :email %>

.....

edit.rhtml is using the partial as follows:

Edit Your Billing Profile

<%= error_messages_for :billing_profile %> <% form_for :billing_profile, @bp, :url => billing_profile_path(@billing_profile), :html => { :method => :put } do |f| %>

<%= render :partial => “profile”, :locals => { :f => f } %>

<%= submit_tag "Update" %>

<% end %>

<%= link_to ‘Show’, billing_profile_path(@bp) %> |
<%= link_to ‘Back’, billing_profiles_path %>

and new.rhtml is using it as follows:

New billing_profile

<%= error_messages_for :billing_profile %>
<% form_for(:billing_profile, :url => billing_profiles_path) do |f| %>

<%= render :partial => “profile”, :locals => { :f => f } %>

<%= submit_tag "Create" %>

<% end %>

<%= link_to ‘Back’, billing_profiles_path %>

My question is how do I use partials for show.rhtml? I used the
scaffold generator of Rails 1.2 and it looks like:

Email: <%=h @billing_profile.email %>

Business phone: <%=h @billing_profile.business_phone %>

...... <%= link_to 'Edit', edit_billing_profile_path(@billing_profile) %> | <%= link_to 'Back', billing_profiles_path %>

I tried several things but it breaks the functional tests. TIA.

You call the partial the same way from two views, and you are wondering
how to call the partial form the third view?

Seems like a silly question. Just use the same cope snippets used the
first two times.

There is a difference. The partial differs from the generated scaffold
because the scaffold has the “h” function that sanitizes the input.

So I don’t think it is possible to use the partial in this case.

Sorry, but it to me it doesn’t make sense if what you want is turn the
show.rhtml into a partial, go ahead and do what Alex suggests.

if you want to use the existing _profile partial whats the point?

that partial contains input fields that are shared between 2 forms. its
a
DRY applied to form’s content. Two form views that share the same input
controls.

On the show view you’ll probably want to output or “show” existing data
so
why use input fields to accomplish that? you’ll be GETing data not
POSTing
nothing.

right?

Jorge

On 12/21/06, Alex W. [email protected] wrote:


Posted via http://www.ruby-forum.com/.

Jorge S.

Bala P. wrote:

There is a difference. The partial differs from the generated scaffold
because the scaffold has the “h” function that sanitizes the input.

So I don’t think it is possible to use the partial in this case.

Are you trying to create a new partial for show.rhtml and not re-use the
_profile.rhtml?

If so, It super easy and works fine with the h() method

#show.rhtml

Some html

<%= render :partial => 'some_other_stuff', :locals => {:foo => @foo} %>

#_some_other_stuff.rhtml
<%=h foo.title %>