how would u do this?

Pardon the newbism :slight_smile: I've inhereted this bit of code and it is being
used in a couple of rhtml files. I'd like to avoid duplicate code by
pulling this out somehow - how would you do this? This is an ecommerce
app and the code is for the credit card expiration date fields.

<code>
<td colspan="2"><%= text_field "orderdetail","month",:class
=>'graymonth',:value =>'mm',:size => '4',:MAXLENGTH =>
2,:onfocus=>"if(this.value=='mm') this.value='';" %> <% if
@is_expiration_month_error != nil and @is_expiration_month_error ==
'false' %>/ <%= text_field "orderdetail","year",:class
=>'graymonth',:value=>'yyyy',:size => '8',:MAXLENGTH =>
4,:onfocus=>"if(this.value=='yyyy') this.value='';" %><% end %></td>
</code>

Thanks.

Pardon the newbism :slight_smile: I've inhereted this bit of code and it is being
used in a couple of rhtml files. I'd like to avoid duplicate code by
pulling this out somehow - how would you do this? This is an ecommerce
app and the code is for the credit card expiration date fields.

You could extract it into a partial you share accross the app.

Fred

good idea :slight_smile: thanks.

Now, I have a partial _foo living under app/views/user and I am trying
to call it from inside bar.rhtml which lives under app/views/purchase

I am getting "Couldn't find template file for purchase/_foo" error

How to get around this?

good idea :slight_smile: thanks.

Now, I have a partial _foo living under app/views/user and I am trying
to call it from inside bar.rhtml which lives under app/views/purchase

I am getting "Couldn't find template file for purchase/_foo" error

How to get around this?

Specify the path to the template, ie render :partial => 'user/
foo' (might need a leading / there, can't remember). I sometimes put
shared partials in a folder called something like shared, so that it
doesn't look like they belong more to one thing than another.

Fred

Frederick Cheung wrote:

I sometimes put
shared partials in a folder called something like shared, so that it
doesn't look like they belong more to one thing than another.

Fred

In my "persnickety-ness", I take that approach one step further by have
an entire directory structure for partials that mirrors the views folder
(and sometimes includes further division). So if I have

app/views
-- order
-- person
-- product

I'll also have

app/views/partials
-- order
-- person
-- product

It might sound like a lot to manage, but since I tend to have a boat
load of partials, it is very well organized and incredibly easy to share
across different resources where they might be needed.

Peace,
Phillip

In my "persnickety-ness", I take that approach one step further by have
an entire directory structure for partials that mirrors the views folder
(and sometimes includes further division). So if I have

app/views
-- order
-- person
-- product

I'll also have

app/views/partials
-- order
-- person
-- product

Do you use the same approach when you have nested resources??

It might sound like a lot to manage, but since I tend to have a boat
load of partials, it is very well organized and incredibly easy to share
across different resources where they might be needed.

Do you put ALL partials in there? or only the shared?

Ya I prefer making a shared or a partials folder i my views where in
I would keep the partials which I use very often ,we can also create a
folder as a nested folder depending upon the purpose.

JON

Thanks for the explanation and your time.

best

j