views:

59

answers:

4

Hello.

I have 2 model classes with different attributes:

class User < ActiveRecord::Base
end

class Subuser < User
end

When I call the 'new' function within controller:

def new
 @subuser = Subuser.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @hosting }
  end
end

and try to access data with view thats held by the Subuser model (migration):

<% form_for(@subuser) do |f| %>
  <%= f.text_field :subname %>
<% end %>

I get:

undefined method `subname' for #

However, if I change it to some other cell that is defined under User model/migration, it will all work okay.

It seems like there are some isssues with the data access.

What am I doing wrong?

Thanks for help!

I get the following error

A: 

From the code posted, @hosting is only defined for format=xml, it won't exist for the HTML view.

Mike Woodhouse
A: 

What is the @hosting variable supposed to be? Mike is right, you aren't defining it anywhere.

My guess is that you probably want to do something more along the lines of

form_for(@subuser) do |f|
bantic
A: 

Are you sure that you are properly using STI (single table inheritance) here? What is your schema for the users table? Are you saying that you have a migration for Subuser... because if you are trying to use STI, it should use the users table with a type column.

Lytol
A: 

Your sub model only knows what it is given via it's parent. So if your trying to access an "imaginary" attribute you will get that undefined method error.

Try added attr_accessor :subname to give it that attribute.

I'm also a bit curious about that @hosting thing...

nowk