Hii I need to pass an array of vlaues from by controller to the partial. Please check my action in my controller def dispfriends @myfriend=[] @myfriendlogin = [] @myusers=[] i=0 @currentgroup = Group.find_by_id(params[:groupid]) puts @currentgroup.id @currentfriendsGroupFriend.find_all_by_user_id_and_group_id(current_user.id,@currentgroup.id) for n in @currentfriends @myfriend=n.friend_id @myusers[i] = User.find_by_id(@myfriend) @myfriendlogin[i]=@myusers[i] puts @myfriendlogin[i] i=i+1 end @myfriendlogin.each do |user| respond_to do |format| format.html { render :partial => ''users/dispfriends'', :collection => @myfriendlogin, :as => :user} end end My Partial <tr> <td class="people_profile"> <div class="clear_float_effect"> <%= link_to user_image_tag(user, 50, :class => ''float_left user_profile_image''), user %> <div class="profile_text_details float_left"> <h5 class="page_heading"><%= hcard_link_to_user user.fullname, user %></h5> </div> </div> </td> </tr> I can only display one user. But, when comes to more than one user I get "Template missing error". Please check my action in the controller and help me in this regard. Thank you. -- 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.
use like this it will send the @myfriendlogin array to partial format.html { render :partial => ''users/dispfriends'', :locals =>{ :user=>@myfriendlogin} -- 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.
Pieter Hugo
2010-May-26 07:37 UTC
Re: How to pass array of values from controller to partial
Hi Ravi Ravi Dtv wrote: @myfriendlogin.each do |user| respond_to do |format| format.html { render :partial => ''users/dispfriends'', :collection => @myfriendlogin, :as => :user} end end --------------------------- I think your problem is in the above piece of code - A controller can only respond to a request once. Your code will work if @myfriendlogin only has one element, but will fail when it has more than one as the webserver cannot send multiple responses back to the browser. The '':collection => '' bit will already tell the partial to iterate through the elements of the collection and apply each element to the partial, so you dont need to put this into a loop. If you just want to pass stuff to the partial you might want to look at '':locals =>'' What are you actually trying to achieve? -- 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.
Pieter Hugo wrote:> Hi Ravi > > Ravi Dtv wrote: > @myfriendlogin.each do |user| > > respond_to do |format| > format.html { render :partial => ''users/dispfriends'', :collection => > @myfriendlogin, :as => :user} > end > > end > > > --------------------------- > I think your problem is in the above piece of code - A controller can > only respond to a request once. Your code will work if @myfriendlogin > only has one element, but will fail when it has more than one as the > webserver cannot send multiple responses back to the browser. > > The '':collection => '' bit will already tell the partial to iterate > through the elements of the collection and apply each element to the > partial, so you dont need to put this into a loop. > > If you just want to pass stuff to the partial you might want to look at > '':locals =>'' > > What are you actually trying to achieve?Thank you for your reply. I tried with locals, but i get the error. When i pass collections i get only one user.But, my requirement is to display all the users in a partial by passing the array form the controller. Thankyou. -- 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.
Michael Pavling
2010-May-26 08:19 UTC
Re: Re: How to pass array of values from controller to partial
On 26 May 2010 08:34, nirosh <kunalan.kandiah-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> use like this it will send the @myfriendlogin array to partial > format.html { render :partial => ''users/dispfriends'', :locals > =>{ :user=>@myfriendlogin}No. There''s no need to use :locals from the controller. The @myfriendlogin is passed automagically to the view. You can use the :collection attribute to let Rails do the iteration from the controller (not very flexible if you want anything else in the view), or do it yourself inside the view to render a partial several times there (see page 119 of the 3rd edition of "Agile Web Development with Rails"). -- 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.
Ravi Dtv
2010-May-26 09:32 UTC
Re: Re: How to pass array of values from controller to partial
Michael Pavling wrote:> On 26 May 2010 08:34, nirosh <kunalan.kandiah-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> use like this it will send the @myfriendlogin array to partial >> format.html { render :partial => ''users/dispfriends'', �:locals >> =>{ :user=>@myfriendlogin} > > No. > > There''s no need to use :locals from the controller. The @myfriendlogin > is passed automagically to the view. > You can use the :collection attribute to let Rails do the iteration > from the controller (not very flexible if you want anything else in > the view), or do it yourself inside the view to render a partial > several times there (see page 119 of the 3rd edition of "Agile Web > Development with Rails").Thank you All for your replies. I got the required output. Thanks. -- 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.
Joao Silva
2010-May-26 11:49 UTC
Re: How to pass array of values from controller to partial
Ravi Dtv, How did you done it after all? Thanks On May 26, 11:32 am, Ravi Dtv <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Michael Pavling wrote: > > On 26 May 2010 08:34, nirosh <kunalan.kand...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> use like this it will send the @myfriendlogin array to partial > >> format.html { render :partial => ''users/dispfriends'', :locals > >> =>{ :user=>@myfriendlogin} > > > No. > > > There''s no need to use :locals from the controller. The @myfriendlogin > > is passed automagically to the view. > > You can use the :collection attribute to let Rails do the iteration > > from the controller (not very flexible if you want anything else in > > the view), or do it yourself inside the view to render a partial > > several times there (see page 119 of the 3rd edition of "Agile Web > > Development with Rails"). > > Thank you All for your replies. > > I got the required output. > > Thanks. > -- > Posted viahttp://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.