Rick DeNatale
2010-Nov-26 16:13 UTC
Helper to generate css-id from AR model. Do I have alzheimers?
On one of the many Rails projects I''ve worked on over the years, I seem to recall using either a helper or a method on a model to generate a css id based on the model class and id. It was very useful particularly in making views more testable in RSpec/Cucumber. I can''t remember if this was part of rails, or from a plugin or something specific to the project. I''ve failed to find anything like this in the rails docs. Any ideas what this might have been? -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Nov-26 17:42 UTC
Re: Helper to generate css-id from AR model. Do I have alzheimers?
On Nov 26, 4:13 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On one of the many Rails projects I''ve worked on over the years, I > seem to recall using either a helper or a method on a model to > generate a css id based on the model class and id. It was very useful > particularly in making views more testable in RSpec/Cucumber. > > I can''t remember if this was part of rails, or from a plugin or > something specific to the project. >Are you thinking of dom_id / dom_class ? Fred> I''ve failed to find anything like this in the rails docs. > > Any ideas what this might have been? > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Github:http://github.com/rubyredrick > Twitter: @RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Rick DeNatale
2010-Nov-26 18:36 UTC
Re: Re: Helper to generate css-id from AR model. Do I have alzheimers?
On Fri, Nov 26, 2010 at 12:42 PM, Frederick Cheung <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Nov 26, 4:13 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On one of the many Rails projects I''ve worked on over the years, I >> seem to recall using either a helper or a method on a model to >> generate a css id based on the model class and id. It was very useful >> particularly in making views more testable in RSpec/Cucumber. >> >> I can''t remember if this was part of rails, or from a plugin or >> something specific to the project. >> > Are you thinking of dom_id / dom_class ?Yes indeed, thanks! -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Github: http://github.com/rubyredrick Twitter: @RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Marnen Laibow-Koser
2010-Nov-28 01:30 UTC
Re: Re: Helper to generate css-id from AR model. Do I have alzheimers?
Rick Denatale wrote in post #964140:> On Fri, Nov 26, 2010 at 12:42 PM, Frederick Cheung > <frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >> Are you thinking of dom_id / dom_class ? > > Yes indeed, thanks!If you''re using Haml, it''s even easier: just use the [@object] syntax.> > -- > Rick DeNataleBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
David Kahn
2010-Nov-28 02:20 UTC
Re: Re: Helper to generate css-id from AR model. Do I have alzheimers?
On Fri, Nov 26, 2010 at 11:42 AM, Frederick Cheung < frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Nov 26, 4:13 pm, Rick DeNatale <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On one of the many Rails projects I''ve worked on over the years, I > > seem to recall using either a helper or a method on a model to > > generate a css id based on the model class and id. It was very useful > > particularly in making views more testable in RSpec/Cucumber. > > > > I can''t remember if this was part of rails, or from a plugin or > > something specific to the project. > > > Are you thinking of dom_id / dom_class ? >Interesting... was not aware of this. Just today was writing a helper method to create a friendly id for an object I am writing to a table row. The challenge with dom_id/class is that when using Cucumber you really do not know (without making a good guess) what the id of a record will be. I am curious if anyone has done or thought of the following for models, something where one defines what fields would constitute a friendly field id which does not involve the index but fields that would be known in a Cucumber scenario? I seem to be writing helpers for this quite often as it seems like often the best strategy for checking for something on a page is to place the data with an id or as a child of some object with a specific id or class. I am not quite sure how to do this as it seems it would have to extend ActiveModel/ActiveRecord...or maybe be done in a module which can be aware of what constituted the friendly_id of a model: include FriendlyId class Borrower < ActiveRecord::Base friendly_id :last_name, :first_name # so in each model you just define what fields of the model will constitute the friendly id end module FriendlyId def friendly_id # how do I access the ''friendly_id'' settings from the model I am mixed in to? end end borrower = Borrower.new(:last_name => "Kahn", :first_name => "David) # using ActiveRecord/ActiveModel borrower.friendly_id>> "kahn_david"or friendly_id(borrower) David> > Fred > > > > I''ve failed to find anything like this in the rails docs. > > > > Any ideas what this might have been? > > > > -- > > Rick DeNatale > > > > Blog:http://talklikeaduck.denhaven2.com/ > > Github:http://github.com/rubyredrick > > Twitter: @RickDeNatale > > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > > LinkedIn:http://www.linkedin.com/in/rickdenatale > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.