PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

PATCH: support nested records in list_column_helpers.rb - get_column_value #746

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have two models, Text1 and Text2, both have attribute 'body', Text1
has_one Text2.
2. I need to display the Text2 as nested and read-only (in Text2 model is
"authorized_for_update?" method, which returns "false") in update form of
Text1.
3. There seems to be no way how to just add some helper method to Text1 or
Text2 helpers, which will only affect the Text2 display (as I mentioned,
both have attribute 'body').
4. So I created this patch. Now it is possible to just add "def
text1_body_column(record); ...; end" to text2s_helper.rb and be done.

If it is acceptable, please include this functionality in active_scaffold
(ideally rails-2.3 branch too).

What version (or revision) of the product are you using?
Fresh rails-2.3 branch.

Original issue reported on code.google.com by r.stu...@googlemail.com on 19 May 2010 at 10:19

Attachments:

GoogleCodeExporter commented 9 years ago
Do you have helper :all in your ApplicationController?

Original comment by sergio.c...@gmail.com on 20 May 2010 at 7:09

GoogleCodeExporter commented 9 years ago
Sorry, I was confused about patching list_column_helpers, I thought you want to
override in text1 list without overriding in text2 list.

You can define your helper and check record's class is Text2:
def body_column(record)
  if record.is_a? Text2
     ...
  else
     ...
  end
end

Is it enough for you?

Original comment by sergio.c...@gmail.com on 20 May 2010 at 7:19

GoogleCodeExporter commented 9 years ago
You're right, this should gain the same results and we need no patch.

Anyway, it will be cool if the code in 'list_column_helpers.rb - 
get_column_value'
method actually checked the availability of the methods in the helpers, which 
are
appropriate for the given records. It will then be much cleaner and I'll need 
only to
create a 'body_column' method in text2 helper.

Thanks for your reply.

Original comment by r.stu...@googlemail.com on 20 May 2010 at 8:07

GoogleCodeExporter commented 9 years ago
Helpers are included in an ActionView::Base instance, so you can't define
body_column in two helper modules and include them, because method from second
helper will override first one.

Original comment by sergio.c...@gmail.com on 20 May 2010 at 8:13

GoogleCodeExporter commented 9 years ago
You can call the different helper methods using this mechanism: 

Text1Controller.helpers.body_column
or
Text2Controller.helpers.body_column

You only need to take care to have the helpers proxy populated with the right 
things.

Original comment by r.stu...@googlemail.com on 20 May 2010 at 8:23

GoogleCodeExporter commented 9 years ago
Now helpers are prefixed with class name, old naming schema continues working 
but it's deprecated

Original comment by sergio.c...@gmail.com on 26 Jul 2010 at 10:03