Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## user.rb has_many :groups has_many :friendships has_many :friends, :through => :friendships, :conditions => ['friendships.accepted = ?', true] #also belongs_to groups (not sure how to set that up) ## group.rb belongs_to :user has_many :groups_users has_many :friends, :class_name => 'User', :through => :groups_users, :foreign_key => "friend_id" ## group_controller.rb (note, edit looks much like this) def create @group = Group.new(params[:group]) @friends = @current_user.friends if request.post? @group.friends = User.find(params[:friend_ids]) if params[:friend_ids] @group.user_id = @current_user.id if @group.save flash[:notice] = "Group Saved Successfully" redirect_to :action => "index", :controller => "memory" else flash[:error] = "Group not saved" end end end ## create.rhtml <p>Friends:<br/> <% for friend in @friends do%> <input type="checkbox" id="<%= friend.id %>" name="friend_ids[]" value="<%=friend.id%>" <% if @group.friends.include? friend %>checked="checked"<% end %> ><%= friend.full_name %></input> <% end %> ## My Question Why doesn't the groups_users row get created when I click save?
This paste will be private.
From the Design Piracy series on my blog: