has_many :through - creating a new model

Hi guys! I'm having this trouble over relationships between models, like this:

     Venue (read a student's tests) ---> Assignment ---> Sheet (read musical sheets)

Here's a video of what I need to accomplish: Articulate - The World's Best Creator Platform for Online Workplace Learning

It's pretty straightforward, I believe: when creating venues, I want to associate sheets to the test, so the student knows what he has to practice for it; through simple checkboxes. Is this achievable with accepts_nested_attributes_for? i'm not sure how to solve this problem and I appreciate your help in enlightening me on this.

Thanks for helping, guys!

Whipped up a small plugin for your use case:

http://github.com/Erol/nested_checklist

In your Venue model:

has_many :assignments

has_many :sheets, :through => :assignments

accepts_nested_checklist_and_attributes_for :sheets

In your VenuesController:

def new

@venue = Venue.new

@venue.build_sheets_checklist

end

def edit

@venue = Venue.find(params[:id]

@venue.build_sheets_checklist

end

Then use nested forms in your views:

<% form_for @venue do |v| %>

<% v.fields_for :sheets do |vs| %>

<%= vs.check_box :checked_for_venue %>

<%= vs.label vs.object.name %>

<% end %>

<%= v.submit %>

<% end %>

I made the plugin rather quickly so I can not guarantee that it works 100%, and there are no test cases. If you find any bugs, just message me.

HTH

I'll go test it and let you know, Erol. Thanks for the kind help.

Hmmm okay looks like it’s bugged when the controller action is edit. Give me a few to fix this.

Commited possible fix. Just pull the updates.