Question : Write a helper in Ruby on Rails

dear experts,

I have a simple helper at ruby on rails (refer to the code below). Although it works fine (no error), but the one that been executed is only the second line. It will only display this image ic_max.png
I am not able to get the first line works.

  def link_to_panel(divname)
    link_to_function image_tag("icon/ic_min.png"), "new Effect.Fade(" + divname + ")"
    link_to_function image_tag("icon/ic_max.png"), "new Effect.Fade(" + divname + ")"
  end

Could you advice about it?

Thanks & regards.

Answer : Write a helper in Ruby on Rails

firstly, i don't know why you are calling link_to_function (which outputs a link to your html) in a helper like you have...

But the issue is that the return value of a function is the result of the last expression (unless return is explicitly called)... SO

def link_to_panel(divname)
    link_to_function image_tag("icon/ic_min.png"), "new Effect.Fade(" + divname + ")"
    link_to_function image_tag("icon/ic_max.png"), "new Effect.Fade(" + divname + ")"
end

returns the output of:
link_to_function image_tag("icon/ic_max.png"), "new Effect.Fade(" + divname + ")"

personally, i'd just put them in the view... but going by your sample

if you want to show both:

def link_to_panel(divname)
    link_to_function image_tag("icon/ic_min.png"), "new Effect.Fade(" + divname + ")" +
    link_to_function image_tag("icon/ic_max.png"), "new Effect.Fade(" + divname + ")"
end

(note the +)
Random Solutions  
 
programming4us programming4us