Hi all,
After working on my first rails app and having handed over some very
sophisticated coding from a lot of you guys. My app does what I want it
to
do, but I’m no where near the end yet, and it seems that the KISS and
DRY
objectives already went down the drain.
It could be lack of knowledge, only doing Ruby on (and) Rails for a
month, but
I’m stuck on the following:
Keeping my code simple seems to influence the ease of use of my
application.
There is functionality in my application that’s very handy and makes you
not
have to repeat yourself with filling out forms. The down side of this is
(seems) that there are pieces of code, duplicated and some statements
are
very complex. And this is not what Rails is about. Does this sound
familiar
to anybody out there?
I’m not going to include my whole app but below is one method that made
me
come to the formentioned dilema.
The models:
company (hm) <-> (bt) contacts
project (ho) <-> (bt) project_contacts
The guilty actions (new_project and create_project) are shown below:
(They’re workin, but I don’t even wanna think about the edit/update
actions)
def new_project
@project = Project.new
@contacts_list = Contact.find_by_sql(‘select t1.name, t2.first_name,
t2.last_name, t2.id from companies AS t1, contacts AS t2 where t1.id =
t2.company_id order by t1.name’)
@contacts_list = @contacts_list.collect { |c| [ c.name + " - " +
c.first_name
- " " + c.last_name, c.id ] }
render_action ‘new_project’
end
def create_project
@contact = Contact.new
@project = Project.new(@params[‘project’])
@project_contact = ProjectContact.new(@params['collect'])
@project.project_contact = @project_contact
contact = Contact.find(@params['id']['collect'])
@project.project_contact.first_name = contact.first_name
@project.project_contact.last_name = contact.last_name
if @project.save
flash[:notice] = 'Project was successfully created.'
redirect_to :action => 'show_project', :id => @project.id
else
render :action => 'edit_project'
end
end
Should I have a clean go. Or shape up, go at it and simply continue?
Regards,
Gerard.
P.S. Thanks a lot for your time if you made it al the way down here!!
–
“Who cares if it doesn’t do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process …”
My $Grtz =~ Gerard;
~
:wq!