I went here- http://wiki.rubyonrails.org/rails/pages/CheckboxHABTM to find out how to do multiple checkboxes with a many-to-many relationship. The problem I am having is that there are other fields in the form which belong to other tables and I am trying to validate everything. There is no problem validating, but when the fields in the other tables aren''t validated the checkboxes are all unchecked if the user checked the boxes. The way I went about it is that I did a flash[notice] for the checkboxes and regular validation functions for the rest of the fields. I have done it in edit and it seems to work but not add. Here is my code: View: <table width=''474'' cellspacing=''0'' cellpadding=''0'' > <% @ctcount = 1 %> <% @checked = ''''%> <% CategoriesTopics.find(:all).each do |@g| %> <% if CategoriesTopicsItem.find(:all, :conditions => [ "categories_topic_id = ? and item_id = ?", @g.id, @item.id]).empty? %> <% @checked = nil %> <% else %> <% @checked = ''checked'' %> <% end %> <%if @ctcount == 1%> <tr> <td valign="top" width="156"><p><%= check_box_tag("item[categories_topic_ids][]", @g.id, @item.categories_topics.include?(@g), :checked => @checked) %> <label for="label_1"><%= @g.topic.topicTitle %></label></p></td> <%elsif @ctcount == 2 %> <td valign="top" width="156"><p><%= check_box_tag("item[categories_topic_ids][]", @g.id, @item.categories_topics.include?(@g), :checked => @checked) %> <label for="label_1"><%= @g.topic.topicTitle %></label></p></td> <%elsif @ctcount == 3 %> <td valign="top" width="156"><p><%= check_box_tag("item[categories_topic_ids][]", @g.id, @item.categories_topics.include?(@g), :checked => @checked) %> <label for="label_1"><%= @g.topic.topicTitle %></label></p></td> </tr> <%else%> <td valign="top" width="156"><p><%= check_box_tag("item[categories_topic_ids][]", @g.id, @item.categories_topics.include?(@g), :checked => @checked) %> <label for="label_1"><%= @g.topic.topicTitle %></label></p></td> <%end%> <% @ctcount = @ctcount + 1 %> <% if @ctcount == 3 %> <% @ctcount = 1 %> <% end %> <% end %> </table> controller: def new @item = Item.new @itemphoto = Itemphoto.new end def create @item = Item.new(params[:item]) @itemphoto = Itemphoto.new(params[:itemphoto]) if !params[''item''][''categories_topic_ids''] flash[:notice] = ''You must provide at least one cause'' render :action => ''new'', :item => @item, :itemphoto => @itemphoto, :categories_topic_ids => params[''item''][''categories_topic_ids''] elsif params[''item''][''categories_topic_ids''].length > 3 flash[:notice] = ''Please provide 3 or fewer causes'' render :action => ''new'', :item => @item, :itemphoto => @itemphoto, :categoriestopics => params[''item''][''categories_topic_ids''] else if @item.save && @itemphoto.save @item.save @item.update_attribute("dateadded", Date.today) @item.update_attribute("datemodified", Date.today) @items_nonprofits = ItemsNonprofits.new @items_nonprofits.update_attribute("nonprofit_id", @session[''user''].nonprofit_id) @items_nonprofits.update_attribute("item_id", @item.id) @itemphoto.save @itemphoto.update_attribute("item_id", @item.id) # Item.find(@item.id).update_attributes(params[:item]) flash[:notice] = ''Item was successfully created.'' redirect_to :action => ''list'' -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---