On Fri, Jun 18, 2010 at 10:39 AM, Mark Sobkowicz <[email protected]> wrote: > I've gone through most of the tutorials, and now I'm making my first app. > It is a > system for my students (I'm a high school teacher) to respond to questions I > post. So I have one model called "Assignment" and another called "Response" . > Responses belong to Assignments and belong to Users. Responses are created > inline on the Assignment 'show' page. > > My current problem is this. I would like users to be able to see all the > responses > for an assignment only after they have responded (at least once) to a > particular > assignment. I'd like to handle this in the response model, by putting > something > appropriate in "view_permitted?". I'll keep working on this, but If anyone > has a > simple recipe or hint, that would be great. >
You could define a predicate on User: def has_responded_to?(assignment) responses.exists?(:assignment_id => assignment.id) end And then in your view_permitted on Response: new_record? || current_user.administrator? || (current_user.signed_in? && current_user.has_responded_to?(assignment)) Note that you can skip the 'signed_in?' check if you define has_responded_to? on your Guest model. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
