Unluckily I can't get this relative simple stuff to work.... :-(
models:
class User < ActiveRecord::Base belongs_to :role, :polymorphic => true
class Admin < ActiveRecord::Base has_one :user, :as => :role
class Dealer < ActiveRecord::Base has_one :user, :as => :role
class Buyer < ActiveRecord::Base has_one :user, :as => :role
dealer controller:
def new @dealer = Dealer.new respond_to do |format| format.html format.xml { render :xml => @dealer } end end
def create @dealer = Dealer.new(params[:dealer]) respond_to do |format| if @dealer.save flash[:notice] = 'Dealer was successfully created.' format.html { redirect_to [:admin, @dealer] } format.xml { render :xml => @dealer, :status => :created, :location => @dealer } else format.html { render :action => "new" } format.xml { render :xml => @dealer.errors, :status => :unprocessable_entity } end end end
error message: ActiveRecord::AssociationTypeMismatch in Admin/dealersController#create User(#41048900) expected, got HashWithIndifferentAccess(#23699520)
Request Parameters:
{"authenticity_token"=>"+GkeOOxVi1Fxl7ccbV0Ctt5R6shyMlF+3UWgRow2RdI=", "dealer"=>{"gender"=>"m", "forename"=>"", "surname"=>"", "company"=>"", "address1"=>"", "address2"=>"", "zipcode"=>"", "city"=>"", "country"=>"1", "user"=>{"email"=>"", "password"=>""}, "phone"=>"", "mobile"=>"", "fax"=>""}, "commit"=>"Submit"}
I guess my problem is that rails doesn't convert the "user" hash inside the request hash into a User object...but why and how can i make rails to do that? :)