Topic: Helper With Form Block

I am trying to refactor a bit of view code in a helper method.

def show_permalink 
   if current_user is_admin?
      "<label for=\"permalink\">Permalink</label>
      #{f.text_field :permalink}"
   end
end

As a result I get shown the label bit, but not the actual text field. I can only assume that this is because I am using a form_for block. If I was dealing with a partial, normally I would pass a local variable to a partial... how would I accomplish something similar here?

Last edited by pimpmaster (2007-05-16 11:10:36)

Re: Helper With Form Block

You can pass the "f" variable like this:

# in form
<%= show_permalink(f) %>

# in helper
def show_permalink(f)
  #..
end

Railscasts - Free Ruby on Rails Screencasts

Re: Helper With Form Block

That is wicked cool!