use like this it will send the @myfriendlogin array to partial
format.html { render :partial => ‘users/dispfriends’, :locals
=>{ :user=>@myfriendlogin}
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 =>’
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”).
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.
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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.