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: 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

On Fri, Oct 15, 2010 at 3:19 AM, Jos M. [email protected]
wrote:

practice for it; through simple checkboxes. Is this achievable with

[email protected][email protected]

.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.


Erol M. Fornoles

http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

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

On Fri, Oct 15, 2010 at 4:31 PM, Jos M. [email protected]
wrote:

http://groups.google.com/group/rubyonrails-talk?hl=en.


Erol M. Fornoles

http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

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

Commited possible fix. Just pull the updates.

On Fri, Oct 15, 2010 at 4:49 PM, Erol F.
[email protected]wrote:

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


Erol M. Fornoles

http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles