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.

<%= 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 %>

Thanks.

On Jul 2, 7:57 pm, nahabed [email protected] wrote:

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?

On Jul 2, 12:08 pm, Frederick C. [email protected]

On Jul 2, 10:12 pm, nahabed [email protected] wrote:

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 C. 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

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?

“Wolas!” wrote:

app/views/partials
– order
– person
– product

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

There is some “debate” about the usefulness of nested resources. I
started to use them, but decided that it was better for me to not. So I
map an invoice resource separately from a customer resource even though
an invoice cannot exist independently. So in my partials subfolder, I
would have folders for customer partials and invoice partials.

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?

I started with having only shared ones in there, but I found that I did
not like having partials in two places, so I moved all of them into that
structure. Now I know where they are without having to think about
whether they are shared or not.

Web Blogger mentioned using a nested folder depending on the purpose of
the partials. I do this too. For example, I have a wizard process for
adding players, coaches, referees, etc to a sports system. These
processes happen via a sports controller, so in my folder structure, I
have

app/views/sports
app/views/partials/sports
app/views/partials/sports/wizard

(I wrote the wizard in such a way that the same partials are used
regardless of whether it’s a player, coach, or referee).

Peace,
Phillip

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

On Jul 3, 3:23 pm, Phillip K. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs