I have a question on what would be the best way to save a HABTM model.
A posting habtm categories, and a category habtm postings.
class Category < ActiveRecord::Base
class Posting < ActiveRecord::Base
In my blog_controller, where the actual posting is saved, is where I
think I’m having some trouble. Here’s what I currently have to save a
@posting = Posting.new(params[:posting])
body_content = @posting.body
body_content.gsub!( /(.*)(\n)/, ‘\1
@posting.body = body_content
@posting.save! @posting.user_id = session[:user_id] logger.debug("Saving the post.") if @posting.save flash[:notice] = 'Posting was successfully created.' redirect_to :controller => 'list', :action => 'index' else render :action => 'new' end
I can successfully load all the categories into a multiple selection
box on the page that is creating the posting, but I’m unsure how to
save the posting.id and the category.id into the categories_postings
table within the ‘create’ action.
There really needs to be a ‘Rails on Relationships’ book for us geeks