I have an index page of ''objects A'' who each have many of another ''object B''. I want to have a link that will open a popup and list all the object B''s of an object A. I have this: <%= link_to( "details of object B", { :controller=>"objectA", :action=>"showObjectBs", :ObjectA => ObjectA}, { :popup=>[''ObjectBs'', ''height=600,width=650,location=no,scrollbars=yes'']} ) %> and then in the action showObjectBs in the Object A controller: def showObjectBs @ObjectBs = ObjectB.find(:all, :conditions => [''objectA_id'' =@ObjectA.id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @objectB} end end but I get an error: ActiveRecord::RecordNotFound in ObjectAsController#show Couldn''t find ObjectA with ID=showObjectBs -- 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.
It seems you have 3 problems with your snippets : First you need to find objectA in your database to use it Then the conditions in the find method doesn''t seem correct Finally you''ve forgottent an ''s'' at the end of @objectB (And the naming convention you''re using is not correct but that''s not the problem) So try with this instead : def showObjectBs @ObjectA = ObjectA.find(params[:id]) @ObjectBs = ObjectB.find(:all, :conditions => [''objectA_id ?'', @ObjectA.id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @objectBs} end end Le 06/04/2010 18:29, ES a écrit :> I have an index page of ''objects A'' who each have many of another > ''object B''. > > I want to have a link that will open a popup and list all the object > B''s of an object A. > > I have this: > > <%= link_to( "details of object B", > { :controller=>"objectA", :action=>"showObjectBs", :ObjectA => > ObjectA}, { :popup=>[''ObjectBs'', > ''height=600,width=650,location=no,scrollbars=yes'']} ) %> > > > and then in the action showObjectBs in the Object A controller: > > def showObjectBs > @ObjectBs = ObjectB.find(:all, :conditions => [''objectA_id'' => @ObjectA.id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @objectB} > end > end > > > but I get an error: > > ActiveRecord::RecordNotFound in ObjectAsController#show > > Couldn''t find ObjectA with ID=showObjectBs > >-- Aurélien AMILIN -- 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.
ES wrote:> I have an index page of ''objects A'' who each have many of another > ''object B''. > > I want to have a link that will open a popup and list all the object > B''s of an object A. >class A has_many :bs end class B belongs_to :a end (AsController) def b_popup @a = A.find(params[:id]) @bs = @a.bs end (A index view) link_to(''test'', {:controller => ''as'', :action => ''b_popup'', :id => a.id}, {:popup => [your stuff here]}) make sure your route in the link_to is available in routes.rb via map.resources for your object A -- 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-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.
AMILIN Aurélien wrote:> So try with this instead : > > def showObjectBs > @ObjectA = ObjectA.find(params[:id]) > @ObjectBs = ObjectB.find(:all, :conditions => [''objectA_id ?'', > @ObjectA.id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @objectBs} > end > endYou should also fix your variable names. The standard ruby convention for variable names is all lower case with underscores separating words. Same goes for method names: def show_object_bs @object_a = ObjectA.find(params[:id]) @object_bs = ObjectB.find(:all, :conditions => [''object_a_id ?'', @object_a.id] ... ... end Notice also that class names begin with upper case, and use camel case to separate words. -- 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-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.