Dear all, I included models, controller and View. Please, find the mistake in it and tell me. I need to fetch the data of included tables "city and country" using the query of "first name and second name" of table ''name''. *name model* has_many :city, :foreign_key => "name_id" has_many :country, :foreign_key => "name_id" * city model* belongs_to :name *country model* belongs_to :name *In Name Controller* @names = Name.find(:all, :conditions=>{:first_name => params[:gm], :second_name => params[:sp]}, :include => [ :city, :country ]) *In Name View* <% @names.each do |name| %> <%= name.age %> <% end %> <% @names.cities.each do |city| %> <%= city.local_area %> <% end %> <% @names.countries.each do |country| %> <%= country.state %> <% end %> -- With Regards Palani Kannan. K -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Sep 23, 12:00 pm, PalaniKannan K <kpalanikan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear all, > > I included models, controller and View. Please, find the mistake in it and > tell me. I need to fetch the data of included tables "city and country" > using the query of "first name and second name" of table ''name''.You could start by stating what the problem is rather than leaving people to guess. Fred> *name model* > has_many :city, :foreign_key => "name_id" > has_many :country, :foreign_key => "name_id" > * > city model* > belongs_to :name > > *country model* > belongs_to :name > > *In Name Controller* > @names = Name.find(:all, :conditions=>{:first_name => params[:gm], > :second_name => params[:sp]}, :include => [ :city, :country ]) > > *In Name View* > > <% @names.each do |name| %> > <%= name.age %> > <% end %> > > <% @names.cities.each do |city| %> > <%= city.local_area %> > <% end %> > > <% @names.countries.each do |country| %> > <%= country.state %> > <% end %> > > -- > With Regards > Palani Kannan. K-- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 September 2010 12:00, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear all, > > I included models, controller and View. Please, find the mistake in it and > tell me. I need to fetch the data of included tables "city and country" > using the query of "first name and second name" of table ''name''. > > name model > has_many :city, :foreign_key => "name_id" > has_many :country, :foreign_key => "name_id"That should be :cities and :countries. You don''t need the foreign key spec, name_id is the default. Colin> > city model > belongs_to :name > > country model > belongs_to :name > > In Name Controller > @names = Name.find(:all, :conditions=>{:first_name => params[:gm], > :second_name => params[:sp]}, :include => [ :city, :country ]) > > In Name View > > <% @names.each do |name| %> > <%= name.age %> > <% end %> > > <% @names.cities.each do |city| %> > <%= city.local_area %> > <% end %> > > <% @names.countries.each do |country| %> > <%= country.state %> > <% end %> > > -- > With Regards > Palani Kannan. K > > -- > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dear Colin, Thanks for your correction. The error solved, but its not still showing the values for <%= city.local_area %> <%= country.state %> On 23 September 2010 17:11, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 23 September 2010 12:00, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Dear all, > > > > I included models, controller and View. Please, find the mistake in it > and > > tell me. I need to fetch the data of included tables "city and country" > > using the query of "first name and second name" of table ''name''. > > > > name model > > has_many :city, :foreign_key => "name_id" > > has_many :country, :foreign_key => "name_id" > > That should be :cities and :countries. You don''t need the foreign key > spec, name_id is the default. > > Colin > > > > > city model > > belongs_to :name > > > > country model > > belongs_to :name > > > > In Name Controller > > @names = Name.find(:all, :conditions=>{:first_name => params[:gm], > > :second_name => params[:sp]}, :include => [ :city, :country ]) > > > > In Name View > > > > <% @names.each do |name| %> > > <%= name.age %> > > <% end %> > > > > <% @names.cities.each do |city| %> > > <%= city.local_area %> > > <% end %> > > > > <% @names.countries.each do |country| %> > > <%= country.state %> > > <% end %> > > > > -- > > With Regards > > Palani Kannan. K > > > > -- > > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > > -- > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- With Regards Palani Kannan. K -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi, I tried with *In View* <% @names.each do |name| %> <%= name.age %> <% name.cities.each do |city| %> <%= city.local_area %> <% name.countries.each do |country| %> <%= country.state %> <% end %> This shows no error with no output of city.local_area and country.state. On 23 September 2010 17:24, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Dear Colin, > > Thanks for your correction. The error solved, but its not still showing the > values for > > <%= city.local_area %> > <%= country.state %> > > > On 23 September 2010 17:11, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 23 September 2010 12:00, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> wrote: >> > Dear all, >> > >> > I included models, controller and View. Please, find the mistake in it >> and >> > tell me. I need to fetch the data of included tables "city and country" >> > using the query of "first name and second name" of table ''name''. >> > >> > name model >> > has_many :city, :foreign_key => "name_id" >> > has_many :country, :foreign_key => "name_id" >> >> That should be :cities and :countries. You don''t need the foreign key >> spec, name_id is the default. >> >> Colin >> >> > >> > city model >> > belongs_to :name >> > >> > country model >> > belongs_to :name >> > >> > In Name Controller >> > @names = Name.find(:all, :conditions=>{:first_name => params[:gm], >> > :second_name => params[:sp]}, :include => [ :city, :country ]) >> > >> > In Name View >> > >> > <% @names.each do |name| %> >> > <%= name.age %> >> > <% end %> >> > >> > <% @names.cities.each do |city| %> >> > <%= city.local_area %> >> > <% end %> >> > >> > <% @names.countries.each do |country| %> >> > <%= country.state %> >> > <% end %> >> > >> > -- >> > With Regards >> > Palani Kannan. K >> > >> > -- >> > 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> > To unsubscribe from this group, send email to >> > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> > For more options, visit this group at >> > http://groups.google.com/group/rubyonrails-talk?hl=en. >> > >> >> -- >> 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > With Regards > Palani Kannan. K > >-- With Regards Palani Kannan. K -- 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 23 September 2010 16:35, PalaniKannan K <kpalanikannan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Please don''t top post it makes it difficult to follow the thread, thanks.> Hi, > > I tried with > > In View > > <% @names.each do |name| %> > <%= name.age %> > <% name.cities.each do |city| %> > <%= city.local_area %> > <% name.countries.each do |country| %> > <%= country.state %> > <% end %> > > This shows no error with no output of city.local_area and country.state.Are you sure it is finding any cities and countries? Try displaying name.cities.count and the same for countries. Even better have a look at the Rails Guide on debugging and use ruby-debug to break in and examine the variables. 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-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.