Determining who is calling a helper method

I have a view calling a helper method is_disabled like this : <%= form.input :company, :label => "Company name", :input_html => { :disabled => is_disabled } %> How can I determine in my helper which element (here :company) is calling the is_disabled method without having to pass a parameter ? Thx by advance for your help.

In what sense is :company calling the method? It is the view code that is calling it.

Colin

I have a lot of elements form calling this method (and the method has to know which element is calling to react) so I wonder is it's possible to know this without having to pas a parameter.

I have a lot of elements form calling this method (and the method has to know which element is calling to react) so I wonder is it's possible to know this without having to pas a parameter.

So in several form_for method calls you call is_disabled as part of building the parameters for the form_for, and you want is_disabled to automatically know the symbol in the first param of the form_for? I think it is unlikely that that is possible. Depending on how the Ruby interpreter (if that is the right word) works, it may not even have looked at the first parameter when it calls is_disabled (other than to check the syntax). There may be some way but I doubt it.

Looking at it from another point of view, what is it that is (or isn't) disabled? It seems like an odd method to be in a view helper.

By the way, please don't top post, it makes it difficult to follow the thread. Thanks.

Colin

Thank you for your reply. I will use a paramater as I thought at the first time.

What about your second remark : my method "is_disabled" is located in the view helper and takes care to enable / disable the input element regarding the rights of the current user.

I retract my comment, that use is fine.

Colin

You might also want to look into subclassing FormBuilder to DRY a lot of this up - essentially, you'd have a custom FormBuilder that has access to the relevant parameters (the object you passed to form_for, the field you're creating a tag for) and can take care adding the :disabled option where appropriate.

--Matt Jones