I have changed my models after you pointed out they were wrong:

class Business < ActiveRecord::Base
  belongs_to :address
  has_many :types
  has_many :categories, :through => :types
end


class Address < ActiveRecord::Base
  has_many :businesses
end


class Category < ActiveRecord::Base
        has_many :types
        has_many :businesses, :through => :types
end


class Type < ActiveRecord::Base
        belongs_to :business
        belongs_to :category
end

I haven't entered the validation in yet, but I will do it later on.
My partial form looks like this:

<h1>New business</h1>

<%= error_messages_for :business %>

<% form_for(@business) do |f| %>
  <p>
    <b>Address</b><br />
    <%= f.text_field :address_id %>
  </p>

  <p>
    <b>Business name</b><br />
    <%= f.text_field :business_name %>
  </p>

  <p>
    <b>Business email</b><br />
    <%= f.text_field :business_email %>
  </p>

  <p>
    <b>Business telephone</b><br />
    <%= f.text_field :business_telephone %>
  </p>

  <p>
    <%= f.submit "Create" %>
  </p>
<% end %>

<%= render :partial=>"new_address", :locals=>{:address=>Address.new}
%>
<%=
render :partial=>"new_category", :locals=>{:category=>Category.new} %>
<%= render :partial=>"new_type", :locals=>{:type=>Type.new} %>
<%= link_to 'Back', businesses_path %>

I've got rid of the multiple create buttons that were present when I
created the form and I am only left with one create button.
How do make the create button save all the data on the form? Also what
validation method do I use to check that the details I want to save
are not already present in the database?


On Feb 16, 11:55 am, Colin Law <clan...@googlemail.com> wrote:
> On 16 February 2010 10:32, Sam <samir_ode...@hotmail.co.uk> wrote:
>
> > class Business < ActiveRecord::Base
> >        has_many :addresses
> >        has_and_belongs_to_many :categories
> >        validates_presence_of :business_name
> > end
>
> > class Category < ActiveRecord::Base
> >        has_and_belongs_to_many :businesses
> >        validates_presence_of :category
>
> Did you mean that?  Table categories has a column category?  So then
> you have, for example, @category.category
>
> Colin

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to