2013-10-02 3 views
0

пытается сделать заявку на выставление счетов, у меня есть 4 модели клиентов, в частности, счет и счетная часть Клиент зарегистрирован и может иметь много счетов, счет может иметь только многие существующие данные, мои модели нижеИдентификатор с ассоциацией HMBT

class Customer < ActiveRecord::Base 
    attr_accessible :name, :ph_no 

    validates :name, :ph_no, :presence => true 

    has_many :bills 
end 


class Particular < ActiveRecord::Base 
    attr_accessible :part_name, :part_qty 

    validates :part_name, :presence => true 

    has_many :billparts 
    has_many :bills, :through => :billparts 
end 

class Bill < ActiveRecord::Base 
    attr_accessible :billdisc, :customer_id 

    validates :billdisc, :customer_id, :presence => true 

    belongs_to :customer 
    has_many :billparts 
    has_many :particulars, :through => :billparts 
end 


class Billpart < ActiveRecord::Base 
    attr_accessible :bill_id, :part_amt, :particular_id 

    belongs_to :bill 
    belongs_to :particular 

end 

мой биллинг контроллер

def new 
    @bill = Bill.new(customer_id: params[:customer_id]) 

    #billpart 
     @all_billparts = Billpart.all 

     @billpart = Billpart.new 

     @all_particulars = Particular.all 

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

мой новый вид счетов

<%= form_for(@bill) do |f| %> 
    <% if @bill.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@bill.errors.count, "error") %> prohibited this bill from being 
saved:</h2> 

     <ul> 
     <% @bill.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :customer_id %><br /> 
    <%= f.number_field :customer_id %> 
    </div> 

<%= form_for(@billpart) do |f| %> 
    <% if @billpart.errors.any? %> 
    <div id="error_explanation"> 
     <h2><%= pluralize(@billpart.errors.count, "error") %> prohibited this billpart 
from being saved:</h2> 

     <ul> 
     <% @billpart.errors.full_messages.each do |msg| %> 
     <li><%= msg %></li> 
     <% end %> 
     </ul> 
    </div> 
    <% end %> 

    <div class="field"> 
    <%= f.label :bill_id %><br /> 
    <%= f.number_field :bill_id %> 
    </div> 
    <div class="field"> 
    <%= f.label :particular_id %><br /> 
    <%= f.collection_select :particular_id, @all_particulars, :id, :part_name %> 
    </div> 
    <div class="field"> 
    <%= f.label :part_amt %><br /> 
    <%= f.number_field :part_amt %> 
    </div> 
    <div class="actions"> 
    <%= f.submit "Add more" %> 
    </div> 
<% end %> 

    <div class="field"> 
    <%= f.label :billdisc %><br /> 
    <%= f.number_field :billdisc %> 
    </div> 
    <div class="actions"> 
    <%= f.submit %> 
    </div> 
<% end %> 

с указанным кодом при попытке создать новый законопроект не будет иметь никакого bill_id и как billpart получить bill_id ассоциировать с

ответ

Смежные вопросы