My controller:

  def index
   @users= User.all

    @users.each do |p|
    @pic= Picture.where(:phrase_id => :route , :culture_id =>
p.culture_id).first
     send_data @pic.image, :type => 'image/gif', :disposition => 'inline'
    end
end

in View

  <tr width = "50%">
 <td><%= image_tag url_for(:controller => "/users", :action => "index"),
:width => "25px", :height => "25px"%></td>

<%@pic.each do |c|%>
  <%= c.image%>
<% end %>


please give me some advices..


thanks
Joanne

On Tue, Jun 21, 2011 at 4:11 AM, Chirag <[email protected]> wrote:

> Hi,
>
> Few things here:
> 1. Would be good if you can paste full code from the beginning of the loop
> till the place where you render picture
> 2. It is not a good practice to set instance variables in the views, set
> them in controller instead
> 3. It is not a good practice to do finds in views, if you want to fetch a
> picture for the user, it's better to define a relationship between picture
> and user models. And then do something like this in the controller - @users
> = User.includes(:picture).all
>
> Hope this helps.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/zIp7YSc9B_MJ.
>
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to