On Tue, Aug 25, 2009 at 1:45 PM, Dhaval
Phansalkar<[email protected]> wrote:
>
> hi all,
>
> i have a has_many :through r'ship in my application. my tables are -
> users, apps(short form for applications), categorizations. i'm trying to
> create a user in new.rhtml where all apps are also shown in checkboxes
> for selection. on submit, user gets created but the join table i.e.
> categorizations table doesn't get updated. where am i going wrong?
> doesn't the join table gets updated automatically? or do i've to update
> it manually? if yes, how? Any help will be greatly appreciated. thanks
> in advance.

I beleive that you need to create the categorizations yourself
something like (this is untested):

> class UsersController < ApplicationController
>  def new
>   �...@user = User.new
>   �...@apps = App.find(:all)
>  end
>
>  def create
>   �...@user = User.new(params[:user])
      params[:user][:app_ids].each do | app_id|
           @user.categorizations << Category.new(:app_id => app_id)
      end
>   �[email protected]!
>    redirect_to(:action => "new")
>    flash[:notice] = "Thanks for signing up!"
>    rescue ActiveRecord::RecordInvalid
>    render :action => 'new'
>  end
> end

HTH


-- 
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to