I asked this on the rails side of this forum but didn't get a response
and while I am using the code in a rails app I think that this is a ruby
question.
In a helper that I am using, I am seeing if a phone # gets entered
correctly, if not default text is entered in it's place and displayed in
red.
This highlets everything in that comes through with 'Click to Edit' in
red. But what I would like to do is to hightlight everything in red if
the string says either 'Click to Edit' of 'Check Format'. So I tried
this:
This codes executes fine but it doesn't show the 'Check Format' part as
red, so I'm thinking that I don't have the conditions set up wrong.
Anyone have any suggestions? Thanks,
I asked this on the rails side of this forum but didn't get a response
and while I am using the code in a rails app I think that this is a ruby
question.
In a helper that I am using, I am seeing if a phone # gets entered
correctly, if not default text is entered in it's place and displayed in
red.
This highlets everything in that comes through with 'Click to Edit' in
red. But what I would like to do is to hightlight everything in red if
the string says either 'Click to Edit' of 'Check Format'. So I tried
this:
This codes executes fine but it doesn't show the 'Check Format' part as
red, so I'm thinking that I don't have the conditions set up wrong.
Anyone have any suggestions? Thanks,
It looks like you've got extra spaces: "Check Format ". Is that
right?
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!
I asked this on the rails side of this forum but didn't get a response
and while I am using the code in a rails app I think that this is a
ruby question.
In a helper that I am using, I am seeing if a phone # gets entered
correctly, if not default text is entered in it's place and displayed
in red.
This highlets everything in that comes through with 'Click to Edit' in
red. But what I would like to do is to hightlight everything in red if
the string says either 'Click to Edit' of 'Check Format'. So I tried
this:
<%= in_place_editor_field 'user','w_phone',{ :style => @user.w_phone
== 'Click
to Edit' ? 'color:red;' : @user.w_phone == "Check Format " ?
^^
I think what David's asking is do you really want to be include those
2 spaces in any comparison?
"Check Format ", and "Check Format" are different.
'color:red;'
: ''}, :cols=>20%>
This codes executes fine but it doesn't show the 'Check Format' part
as red, so I'm thinking that I don't have the conditions set up wrong.
Anyone have any suggestions? Thanks,
-S
cheers,
···
On Thu, 20 Mar 2008 09:01:48 -0500 Shandy Nantz <shandybleu@yahoo.com> wrote:
to Edit' ? 'color:red;' : ''}, :cols=>20%>
: ''}, :cols=>20%>
This codes executes fine but it doesn't show the 'Check Format' part as
red, so I'm thinking that I don't have the conditions set up wrong.
Anyone have any suggestions? Thanks,
It looks like you've got extra spaces: "Check Format ". Is that
right?
David
It's for formatting, but I can get rid of it if that is causing a
problem. Ruby on Rails was the book that I read when I was first
learning rails - great book.
This codes executes fine but it doesn't show the 'Check Format' part
as red, so I'm thinking that I don't have the conditions set up wrong.
Anyone have any suggestions? Thanks,
Why not use a regular expression? They're fairly straightforward when
you control the strings to this extent.
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.
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).
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.
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!
module ApplicationHelper
def check_red_style(input,test=/Click to edit|Check format/)
(input=~test) ? {:style=>'color:red'} : {}
end
end
That worked beautifully, thank you. Just out of curiosity, can I do an
if-elsif statement the way that I was trying? Can I have one conditional
if statement within another to form a conditional if-elsif statement?
Thanks,
irb(main):001:0> a = false
=> false
irb(main):002:0> b = true
=> true
irb(main):003:0> a ? "a is true" : b ? "b is true" : "b is false"
=> "b is true"
Jesus.
···
On Fri, Mar 21, 2008 at 3:41 PM, Shandy Nantz <shandybleu@yahoo.com> wrote:
Just out of curiosity, can I do an
if-elsif statement the way that I was trying? Can I have one conditional
if statement within another to form a conditional if-elsif statement?
Thanks,