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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 September 2010 20:17, proximal <lph.engelmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 ?In what sense is :company calling the method? It is the view code that is calling it. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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. On Sep 2, 10:15 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 2 September 2010 20:17, proximal <lph.engelm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In what sense is :company calling the method? It is the view code > that is calling it. > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 2 September 2010 21:41, proximal <lph.engelmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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> > On Sep 2, 10:15 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 2 September 2010 20:17, proximal <lph.engelm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> In what sense is :company calling the method? It is the view code >> that is calling it. >> >> Colin > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 2, 10:52 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 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.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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 3 September 2010 07:55, proximal <lph.engelmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 2, 10:52 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> 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. > > 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 received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 3, 2:55 am, proximal <lph.engelm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 2, 10:52 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > 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. > > 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.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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.