Newbie question - how do I hide/show a div using pure rails?

Hi Sean,

You could put something like this in you application helper; based on
the condition, it will wrap what's in the block with your anchor tags.
The key is concating something to the block binding.

def link_if(condition, &proc)
  if condition
    start_anchor = '<a href="#"
onclick="Effect.toggle('edit_project_name', 'appear', {duration: .5});
return false;">'
    end_anchor = '</a>'
    concat(start_anchor, proc.binding)
    yield
    concat(end_anchor, proc.binding)
  else
    yield
  end
end

Then in your view you'd put this:

<% link_if @isopen do %>
  Project name:
<% end %>

That's a lot cleaner.

Jim

Or put something a lot more general in your helper:

# descended from the union of link_to_unless and link_to_function

Jim,

You should try to take a look at the "Show Source" in the Rails RDocs. While it can sometimes seem like you're falling down a rabbit-hole as little 3-5 line methods call other methods which call still others, you can open up the source file and browse through it. Most of the code is quite well written and it's a great way to learn more about Ruby.

-Rob

Rob Biedenharn http://agileconsultingllc.com
Rob@AgileConsultingLLC.com