Pardon the newbism :) 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 2, 7:57 pm, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Pardon the newbism :) 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> <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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
good idea :) 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 Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 2, 7:57 pm, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Pardon the newbism :) 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 > > > <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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jul 2, 10:12 pm, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> good idea :) 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> > On Jul 2, 12:08 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On Jul 2, 7:57 pm, nahabed <roup...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Pardon the newbism :) 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 > > > > <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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. > > FredIn 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 > -- productDo 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?> > Peace, > Phillip > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 -------- On Jul 3, 12:56 pm, "\"Wolas!\"" <jcpen...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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? > > > > > Peace, > > Phillip > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
"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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for the explanation and your time. best j On Jul 3, 3:23 pm, Phillip Koebbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> "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 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---