Re: Single inheritance with nested attributes routing problem

JDevine
Sun, 01 Nov 2009 19:58:11 -0000

You have a naming mismatch between "BaseDetail" and
"BasicDetail"

On Nov 1, 1:39 pm, James Cook
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> I am working on a project that involves many different types of users,
> each with their own sets of information. I decided to condense the
> variety of users into a single class to deal with things like logging
> into the site, and use single table inheritance to account for the rest
> of the logic. Since the different user types require different
> information I made new models to store this extra information, linking
> them back into the relevant classes with has_many and belongs_to.
>
> The trouble comes up when I try to load a form creating a new user and
> their information. I receive this error:
>
>     uninitialized constant BasicUser::BaseDetail
>
> The parts of code I think might be relevant are:
>
>
------------------------------------------------------------------------------
> #user.rb
> class User < ActiveRecord::Base
> end
>
> #basic_user.rb
> class BasicUser < User
>      has_one :details, :class_name => ''BaseDetail'',
:foreign_key =>
> "user_id"
>      accepts_nested_attributes_for :details, :allow_destroy => true
> end
>
> #basic_detail.rb
> class BasicDetail < ActiveRecord::Base
>      belongs_to :basic_user
> end
>
> #routes.rb
> map.resources :basic_users, :controller => ''user''
> map.resources :users
>
> #register.html
> <% form_for @user do |user| %>
>      <% fields_for @user.details do |details| %>
>            #some form stuff
>      <% end %>
>      #more form stuff
> <% end %>
>
> #home_controller.rb
> def register
>      if !param_exists? :user
>           @user = BasicUser.new
>      end
>      if param_posted? :user
>           @user = BasicUser.new(params[:user])
>           if @user.save
>                redirect_to :controller => "user"
>           end
>      end
> end
>
------------------------------------------------------------------------------
>
> I''ve been working with Rails 1.2.6 up until now (I wanted to use
> accepts_nested_attributes_for) and so this is my first day with the new
> version. I have very little understanding of routes, and indeed the only
> reason I have them there at all is because without them I get the error
> "undefined method `basic_users_path'' for
#<ActionView::Base:0x5a51db0>."
>
> On a similar note, rails has become much slower since I updated to
> 2.3.5. Can this be fixed, or is it probably just my computer being
> worthless?
>
> Thanks
> -Jaheco
> --
> Posted viahttp://www.ruby-forum.com/.