Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>on a slightly different tack.</p> <p>The idea of using a class method to do this feels wrong from an OO point of view.</p> <p>You should really refactor this so that it works from an instance method. </p> <pre> def personal_data_module item_module = Hpricot(body) { :studies => (item_module/"studies").inner_html, :birth_place => (item_module/"birth_place").inner_html, :marrital_status => (item_module/"marrital_status").inner_html } end </pre> <p>Then, where you need to use it, instead of doing....</p> <pre> Foobar.get_personal_data_module(the_id) </pre> <p>you would do</p> <pre> Foobar.find_by_person_id(the_id).personal_data_module </pre> <p>This looks worse, but in fact, thats a bit artificial, normally, you would be referencing this from some other object, where in fact you would have a 'handle' on the person object, so would not have to construct it yourself.</p> <p>For instance, if you have another class, where you reference person_id as a foreign key, you would have</p> <p>class Organisation belongs_to :person end</p> <p>then, where you have an organisation, you could go</p> <pre> organisation.person.personal_information_module </pre> <p>Yes, I know, that breaks demeter, so it would be better to wrap it in a delegate</p> <pre> class Organisation belongs_to :person def personal_info_module person.personal_info_module end end </pre> <p>And then from controller code, you could just say</p> <pre> organisation.personal_info_module </pre> <p>without worrying about where it comes from at all.</p> <p>This is because a 'personal_data_module' is really an attribute of that class, not something to be accessed through a class method.</p> <p>But this also brings up some questions, for instance, is person_id the primary key of this table? is this a legacy situation where the primary key of the table is not called 'id'?</p> <p>If this is the case, have you told ActiveRecord about this or do you have to use 'find_by_person_id' all over where you would really want to write 'find'?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload