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,
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?
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.
On Thu, 20 Mar 2008 09:01:48 -0500
Shandy N. [email protected] wrote:
to Edit' ? 'color:red;' : ''}, :cols=>20%>
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,
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).
(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.
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,
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,
Something like this?
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.