Почему рельсы не сохраняют поле типа в наследовании одной таблицы - PullRequest
2 голосов
/ 29 ноября 2011

У меня есть модель клиента с наследованием одной таблицы.Но когда я пытаюсь отправить форму, поле типа не сохраняется в базе данных.Как заставить его сохранить тип, а затем отобразить тип учетной записи на index.html.erb.

models / client.rb

class Client < ActiveRecord::Base

end

class Suscriber < Client

end

class NonSuscriber < Client

end 

views / _form.html.erb

    <%= simple_form_for @client do |f| %>

      <%= f.input :name %>
      <%=f.input :type %>

      <%= f.button :submit %>   


<% end %>

clients_controller.rb

def index
  @clients = Client.where(:type => params[:type])
    respond_to do |format|
      format.html
      format.json {render json: @clients}
    end
end 


 def new
   @client = Client.new 

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

def create
    @client = Client.new(params[:client])

    respond_to do |format|
      if @client.save
        format.html { redirect_to @clinet, :notice => 'Client was successfully created.' }
        format.json { render :json => @client, :status => :created, :location => @client }
      else
        format.html { render :action => "new" }
        format.json { render :json => @client.errors, :status => :unprocessable_entity }
      end
    end
  end      

Я на рельсах 3.1

1 Ответ

2 голосов
/ 29 ноября 2011

документы говорят:

"Active Record позволяет наследовать, сохраняя имя класса в столбце, который по умолчанию называется" тип "(можно изменить, переписав Base.наследство_колонка. "

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...