From: "David A. Black" Date: 2008-03-21T21:17:52+09:00 Subject: Re: if-less if statements Hi -- On Fri, 21 Mar 2008, Paul Mckibbin wrote: > Paul Mckibbin wrote: >>> On Thu, 20 Mar 2008 09:01:48 -0500 >>>> Anyone have any suggestions? Thanks, >> > > Actually, and this is definitely more appropriate to the rails forum, > you should really have this in you user_helper.rb or > application_helper.rb file and called it from the view. > > e.g. > > In the view: > > <%= in_place_editor_field 'user','w_phone', > check_red_style(@user.w_phone), :cols=>20%> > > > In the application_helper.rb file: > > module ApplicationHelper > def check_red_style(input,test=/Click to edit|Check format/) > (input=~test) ? {:style=>'color:red'} : {} > end > end > > and then you can use whatever regular expression you want from the view > (although check that you can have nested helpers, I don't think it's a > problem, but I don't have a scratch rails area to test it on). They're just instance methods available to the current object, so you can have as any as you like. David -- Upcoming Rails training from David A. Black and Ruby Power and Light: ADVANCING WITH RAILS, April 14-17 2008, New York City CORE RAILS, June 24-27 2008, London (Skills Matter) See http://www.rubypal.com for details. Berlin dates coming soon!