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
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
end
class Address
In your previous post you said this:
a business can only have one address but an address can have one or
many businesses
Your models are then set up wrong. They should be:
class Business
belongs_to :address
class Address
has_many :businesses
A tip:
validates_presence_of :street_name
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
Hi thanks for the info.
Here is the link containing the code and an image of the form:
https://gist.github.com/a3676da061799ac6e29d
On Feb 11, 11:34 am, Sharagoz -- li...@ruby-forum.com wrote:
If the code is too long to copy/paste directly into the post, then you
can create a public gist on
Here's what you can do:
First, edit all the form partials and remove the form tags so that only
the fields are left.
I dont know what the relationship between the models are. Is it business
has one category and has one address? If so, the form would look
something like:
% form_for(@business)
I tried the code and I get the following error message:
NoMethodError in Businesses#new
Showing businesses/new.html.erb where line #21 raised:
undefined method `address' for #Business:0x3220350
Extracted source (around line #21):
18: %= f.text_field :website %
19: /p
20:
21: %
Can you show us how the model associations for Business, Address and
Category?
E.G:
class Address ActiveRecord::Base
has_many :businesses
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups Ruby
on Rails: Talk group.
Thanks for replying, I'd like to post an image but Iseem to be having
a few issues posting the link on here, I used image shack to upload
the image of the form but I cannot post the direct link or embedded
link, i keep getting an error message saying We were unable to post
your message. Not sure
If the code is too long to copy/paste directly into the post, then you
can create a public gist on github and link to that:
http://gist.github.com/
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups Ruby
on Rails: Talk
It would help if you show us the form(s)
--
Posted via http://www.ruby-forum.com/.
--
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,
11 matches
Mail list logo