views:

82

answers:

2

This is probably easy but I'm a bit of a newbie on wrapping my head around these things sometimes.

Synopsis: I'm trying to make a checklist application that technicians go through and answer questions about what has been completed or done in the field. The technicians then submit this for review. The questions are created, managed, and updated by the managers.

UPDATE I'm a designer, so I naturally magnetize to PS. Here's a photo of the concept: http://screensnapr.com/u/a9k1ps.png

checklist model contains: header, subheader, question, and answer.

Everything is a string, except the answer field, which is an integer for a check box.

I'm not quite sure which RESTful page to start with after that though. I need the header displayed like this (in view), but editable/submittable through the check box all on one page.

This view has to DISPLAY the checklist and EDIT the checklist at the same time. The manager needs to be able to add new headers, subheaders, and questions, which the technicians can then answer.

<% @checklists.each do |checklist| %>
<h1> <%=h checklist.header %> </h1>
<h3> <%=h checklist.subheader %> </h3>
<ul>
   <li>
  <%=h checklist.question %>
  <% form_for @checklists do |f| %>
  <%= f.check_box("checklist", "answer") %>
  <% end %>
  </li>
</ul>
<% end %>

Would this work and would it best to stick this in the index or edit action? Would I be better doing a partial of some sort? nested_attributes? I'm a bit lost at this point because I'm trying to manage two actions (index, edit) within one file.

A: 

Without looking at this further, I'm willing to bet you want form_for checklist.question and POST to questions_controller, which would use the #update action.

scottburton11
It's only the checklist controller that exists. So I would put this above information in the index page, and then have the form_for action POST to the update action? Do I just use :method => POST on the form_for tag? How do I go about having it update itself when the form_for submit button is clicked?
Branden Silva
Your answer does not seem to help at all... At least I really do not understand what you are saying.
Veger
I appreciate your response scott, even if it wasn't what I needed.
Branden Silva
+2  A: 

If you want a manager to update/modify the checkboxes and the technicians to fill in the forms, you need a couple of extra tables. One containing the questions and one containing the values that are checked. Also, it seems better to split the controller into two, one for each user type:

For the manager part you can simply make a controller like any other controller: using the index action to show all questions and the edit/update/etc actions to modify them.

For the technician part you need to define a project table, containing some information about the project the technician is working on. And a checkboxes table containing the project_id and the checkbox_ids, in order to link the checkboxes to a certain project.

See A Guide to Active Record Associations for more information about creating associations between tables.

Veger
Thanks for the response Vegar. I've been trying to wrap my head around the has_many :through relationships for some time. I do know how to do them, but I have a hard time understanding how to access them all through different controllers/views and such. Many tutorials show how to associate them in the models, but not in the views/controllers. I have successfully done a has_many_belongs_to relationship, which I believe creates the XXX_ids for me, but of course does not allow additional info put in the relationship. I'll mash around in Aptana to see if I can figure this out.
Branden Silva
I've updated the thread with a picture too. Just to make sure we are on the same page.
Branden Silva
You do not need to build a controller for each Model. You need controllers for the pages you want to show. So one for the managers and one for the technicians. The associations are automatically fetched when fetching the base record, using the autmatically added id field(s).
Veger
Branden Silva
Something like that yes
Veger