Hi all, I have very basic error that i have no idea how to show I have user table id name add phone number then i select all in user table using => @users = User.all => @users.name it gives me undefined method name Array<.....> Please give me some advice.. Thanks -- 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.
@users.all basically returns "array" of users so you have to iterate through this array @users.each do |user| puts user.name end tom On Jun 20, 2011, at 18:33 , Yennie wrote:> Hi all, I have very basic error that i have no idea how to show > > I have user table > id > name > add > phone number > > > then i select all in user table > using => @users = User.all > > => @users.name > > it gives me undefined method name Array<.....> > > Please give me some advice.. > > > Thanks > > -- > 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.-- ==============================================================================Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz ============================================================================== -- 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! The method User.all returns an Array of users, not a single user. I think you have to iterate over the array, using each. @users.each { |u| u.name } Everaldo On Mon, Jun 20, 2011 at 1:33 PM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, I have very basic error that i have no idea how to show > > I have user table > id > name > add > phone number > > > then i select all in user table > using => @users = User.all > > => @users.name > > it gives me undefined method name Array<.....> > > Please give me some advice.. > > > Thanks > > -- > 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.
thanks On Mon, Jun 20, 2011 at 12:38 PM, Everaldo Gomes <everaldo.gomes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Hi! > > The method User.all returns an Array of users, not a single user. > > I think you have to iterate over the array, using each. > > @users.each { |u| u.name } > > Everaldo > > > On Mon, Jun 20, 2011 at 1:33 PM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Hi all, I have very basic error that i have no idea how to show >> >> I have user table >> id >> name >> add >> phone number >> >> >> then i select all in user table >> using => @users = User.all >> >> => @users.name >> >> it gives me undefined method name Array<.....> >> >> Please give me some advice.. >> >> >> Thanks >> >> -- >> 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. >-- -------------------------------- Thank you, Yen -- 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.
I have other undefined method when i combine the code above together <%@users = User.all%> <%@users.each do |u|%> <%u.culture_id%> <% @pic= Picture.where(:phrase_id => :route , :culture_id => u.culture_id).first%> <td>My picture <%= @pic.image%></td> and it causes undefined method image please give me advices.... thank you so much Joanne On Mon, Jun 20, 2011 at 12:48 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks > > On Mon, Jun 20, 2011 at 12:38 PM, Everaldo Gomes <everaldo.gomes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > wrote: > >> Hi! >> >> The method User.all returns an Array of users, not a single user. >> >> I think you have to iterate over the array, using each. >> >> @users.each { |u| u.name } >> >> Everaldo >> >> >> On Mon, Jun 20, 2011 at 1:33 PM, Yennie <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Hi all, I have very basic error that i have no idea how to show >>> >>> I have user table >>> id >>> name >>> add >>> phone number >>> >>> >>> then i select all in user table >>> using => @users = User.all >>> >>> => @users.name >>> >>> it gives me undefined method name Array<.....> >>> >>> Please give me some advice.. >>> >>> >>> Thanks >>> >>Joanne> >>> -- >>> 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. >> > > > >-- 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 20 June 2011 17:53, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have other undefined method when i combine the code above together > > <%@users = User.all%> > <%@users.each do |u|%> > <%u.culture_id%> > > <% @pic= Picture.where(:phrase_id => :route , :culture_id => > u.culture_id).first%> > <td>My picture <%= @pic.image%></td> > > and it causes undefined method imageWhat does it say has not got a method image? It is always a good idea to post the complete error message (use copy/paste rather than re-typing it). If it says the nil has not got the method then your call of Picture.where has not found a record. 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
the error is undefined method `image'' for nil:NilClass On Mon, Jun 20, 2011 at 2:42 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 20 June 2011 17:53, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I have other undefined method when i combine the code above together > > > > <%@users = User.all%> > > <%@users.each do |u|%> > > <%u.culture_id%> > > > > <% @pic= Picture.where(:phrase_id => :route , :culture_id => > > u.culture_id).first%> > > <td>My picture <%= @pic.image%></td> > > > > and it causes undefined method image > > What does it say has not got a method image? It is always a good idea > to post the complete error message (use copy/paste rather than > re-typing it). If it says the nil has not got the method then your > call of Picture.where has not found a record. > > 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. > >-- -------------------------------- Thank you, Yen -- 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 don''t have an <% end %> to close the <% @users.each %> block in the code you included, so my guess is that your u variable is already out of scope by the time you call u.image. On Mon, Jun 20, 2011 at 9:08 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> the error is undefined method `image'' for nil:NilClass > > > On Mon, Jun 20, 2011 at 2:42 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > >> On 20 June 2011 17:53, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > I have other undefined method when i combine the code above together >> > >> > <%@users = User.all%> >> > <%@users.each do |u|%> >> > <%u.culture_id%> >> > >> > <% @pic= Picture.where(:phrase_id => :route , :culture_id => >> > u.culture_id).first%> >> > <td>My picture <%= @pic.image%></td> >> > >> > and it causes undefined method image >> >> What does it say has not got a method image? It is always a good idea >> to post the complete error message (use copy/paste rather than >> re-typing it). If it says the nil has not got the method then your >> call of Picture.where has not found a record. >> >> 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. >> >> > > > -- > -------------------------------- > > Thank you, > > Yen > > > -- > 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.
On 20 June 2011 20:08, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: Please don''t top post, it makes it difficult to follow the thread. Insert your reply at appropriate places in previous message. Thanks.> the error is undefined method `image'' for nil:NilClassSo what does that mean (see my previous post)? Colin> > On Mon, Jun 20, 2011 at 2:42 PM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> >> On 20 June 2011 17:53, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > I have other undefined method when i combine the code above together >> > >> > <%@users = User.all%> >> > <%@users.each do |u|%> >> > <%u.culture_id%> >> > >> > <% @pic= Picture.where(:phrase_id => :route , :culture_id => >> > u.culture_id).first%> >> > <td>My picture <%= @pic.image%></td> >> > >> > and it causes undefined method image >> >> What does it say has not got a method image? It is always a good idea >> to post the complete error message (use copy/paste rather than >> re-typing it). If it says the nil has not got the method then your >> call of Picture.where has not found a record. >> >> 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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > > -- > 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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 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.
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 <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 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.
> 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 %> > > error is >You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each Extracted source (around line #79): 76: <tr width = "50%"> 77: <td><%= image_tag url_for(:controller => "/users", :action => "index"), :width => "25px", :height => "25px"%></td> 78: 79: <%@pic.each do |c|%> 80: <%= c.image%> 81: <% end %> 82: please give me some advices..> > > thanks > Joanne > > > >-- 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.
Your index action should be something like this: def index @users= User.all @pic = [] @users.each do |p| @pic << Picture.where(:phrase_id => :route , :culture_id => p.culture_id).limit(1) end end -- 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/-/B259TKI0970J. 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 does not work, it is complaining other error NoMethodError (undefined method `image'' for [nil]:Array): app/controllers/patients_controller.rb:27:in `block in index'' app/controllers/patients_controller.rb:25:in `each'' app/controllers/patients_controller.rb:25:in `index'' On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Your index action should be something like this: > > def index > @users= User.all > @pic = [] > > @users.each do |p| > @pic << Picture.where(:phrase_id => :route , :culture_id => > p.culture_id).limit(1) > end > end > > -- > 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/-/B259TKI0970J. > > 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. >-- -------------------------------- Thank you, Yen -- 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.
Oh yes... sorry about that. I assumed that you will find picture for every query. You can try this instead: def index @users= User.all @pic = [] @users.each do |p| @pic << Picture.where(:phrase_id => :route , :culture_id => p.culture_id).limit(1) end @pic.compact! end by calling compact! on the array, we will eliminate all nil object. On another note, are you sure, this is what you want to do? If you have 100 users, it will fire 100 sql queries which is not good. On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> it does not work, it is complaining other error > > NoMethodError (undefined method `image'' for [nil]:Array): > app/controllers/patients_controller.rb:27:in `block in index'' > app/controllers/patients_controller.rb:25:in `each'' > app/controllers/patients_controller.rb:25:in `index'' > > > > On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: > >> Your index action should be something like this: >> >> def index >> @users= User.all >> @pic = [] >> >> @users.each do |p| >> @pic << Picture.where(:phrase_id => :route , :culture_id => >> p.culture_id).limit(1) >> end >> end >> >> -- >> 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/-/B259TKI0970J. >> >> 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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > > > -- > 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. >-- Chirag http://sumeruonrails.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.
On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Oh yes... sorry about that. > I assumed that you will find picture for every query. > > You can try this instead: > def index > @users= User.all > @pic = [] > > @users.each do |p| > @pic << Picture.where(:phrase_id => :route , :culture_id => > p.culture_id).limit(1) > end > @pic.compact! > end > > by calling compact! on the array, we will eliminate all nil object. > > On another note, are you sure, this is what you want to do? If you have 100 > users, it will fire 100 sql queries which is not good. > > Yes i think i have that problem as well because if i remove "@users.eachdo |p| " and then it will cause undefined method of culture_id.. plus when i call @pic.compact! , it gives me NoMethodError (You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.compact!): app/controllers/patients_controller.rb:29:in `index'' what is mean? cuz i want to display picture on the browser too... please help... thank you very much Joanne> > > On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> it does not work, it is complaining other error >> >> NoMethodError (undefined method `image'' for [nil]:Array): >> app/controllers/patients_controller.rb:27:in `block in index'' >> app/controllers/patients_controller.rb:25:in `each'' >> app/controllers/patients_controller.rb:25:in `index'' >> >> >> >> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >> > wrote: >> >>> Your index action should be something like this: >>> >>> def index >>> @users= User.all >>> @pic = [] >>> >>> @users.each do |p| >>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>> p.culture_id).limit(1) >>> end >>> end >>> >>> -- >>> 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/-/B259TKI0970J. >>> >>> 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. >>> >> >> >> >> -- >> -------------------------------- >> >> Thank you, >> >> Yen >> >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- 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.
Can you paste what you have in your index method? You should not be getting this error because we have already defined @pic as an empty array. On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > wrote: > >> Oh yes... sorry about that. >> I assumed that you will find picture for every query. >> >> You can try this instead: >> def index >> @users= User.all >> @pic = [] >> >> @users.each do |p| >> @pic << Picture.where(:phrase_id => :route , :culture_id => >> p.culture_id).limit(1) >> end >> @pic.compact! >> end >> >> by calling compact! on the array, we will eliminate all nil object. >> >> On another note, are you sure, this is what you want to do? If you have >> 100 users, it will fire 100 sql queries which is not good. >> >> Yes i think i have that problem as well because if i remove "@users.each > do |p| " > and then it will cause undefined method of culture_id.. > plus when i call @pic.compact! , it gives me > > NoMethodError (You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.compact!): > app/controllers/patients_controller.rb:29:in `index'' > > what is mean? cuz i want to display picture on the browser too... > > please help... thank you very much > > Joanne > >> >> >> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> it does not work, it is complaining other error >>> >>> NoMethodError (undefined method `image'' for [nil]:Array): >>> app/controllers/patients_controller.rb:27:in `block in index'' >>> app/controllers/patients_controller.rb:25:in `each'' >>> app/controllers/patients_controller.rb:25:in `index'' >>> >>> >>> >>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Your index action should be something like this: >>>> >>>> def index >>>> @users= User.all >>>> @pic = [] >>>> >>>> @users.each do |p| >>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>> p.culture_id).limit(1) >>>> end >>>> end >>>> >>>> -- >>>> 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/-/B259TKI0970J. >>>> >>>> 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. >>>> >>> >>> >>> >>> -- >>> -------------------------------- >>> >>> Thank you, >>> >>> Yen >>> >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > > -- > 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. >-- Chirag http://sumeruonrails.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.
Can you paste what you have in your index method?> You should not be getting this error because we have already defined @pic > as an empty array. > >> def index > @users= User.all > @pic= [] > > @users.each do |p| > @pic<< Picture.where(:phrase_id => :route , :culture_id => > p.culture_id).first > > end > > @pic.compact! > send_data @pic.image, :type => ''image/png'', :disposition => ''inline'' > > end > > On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> Oh yes... sorry about that. >>> I assumed that you will find picture for every query. >>> >>> You can try this instead: >>> def index >>> @users= User.all >>> @pic = [] >>> >>> @users.each do |p| >>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>> p.culture_id).limit(1) >>> end >>> @pic.compact! >>> end >>> >>> by calling compact! on the array, we will eliminate all nil object. >>> >>> On another note, are you sure, this is what you want to do? If you have >>> 100 users, it will fire 100 sql queries which is not good. >>> >>> Yes i think i have that problem as well because if i remove "@users.each >> do |p| " >> and then it will cause undefined method of culture_id.. >> plus when i call @pic.compact! , it gives me >> >> NoMethodError (You have a nil object when you didn''t expect it! >> You might have expected an instance of Array. >> The error occurred while evaluating nil.compact!): >> app/controllers/patients_controller.rb:29:in `index'' >> >> what is mean? cuz i want to display picture on the browser too... >> >> please help... thank you very much >> >> Joanne >> >>> >>> >>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> it does not work, it is complaining other error >>>> >>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>> app/controllers/patients_controller.rb:25:in `each'' >>>> app/controllers/patients_controller.rb:25:in `index'' >>>> >>>> >>>> >>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> Your index action should be something like this: >>>>> >>>>> def index >>>>> @users= User.all >>>>> @pic = [] >>>>> >>>>> @users.each do |p| >>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>> p.culture_id).limit(1) >>>>> end >>>>> end >>>>> >>>>> -- >>>>> 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/-/B259TKI0970J. >>>>> >>>>> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> -------------------------------- >>>> >>>> Thank you, >>>> >>>> Yen >>>> >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Chirag >>> http://sumeruonrails.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. >>> >> >> >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- -------------------------------- Thank you, Yen -- 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 Tue, Jun 21, 2011 at 8:05 AM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:>> def index >> @users= User.all >> @pic= []You would probably have fewer problems if you observed the Rails naming conventions; e.g. @pictures = [] # plural @users.each do |user| @pictures << Picture.where(:phrase_id => :route , :culture_id =>user.culture_id).first end @pictures.compact! Now it''s obvious that the next line makes no sense: send_data @pictures.image, :type => ''image/png'', :disposition => ''inline'' An *array* of pictures doesn''t have an "image" attribute. HTH, -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
1. Remove the send_data line, it isn''t required. 2. Can you check if there are any records in your pictures table? Right now it looks like it is returning nil. On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Can you paste what you have in your index method? >> You should not be getting this error because we have already defined @pic >> as an empty array. >> >> > > >> def index >> >> @users= User.all >> @pic= [] >> >> @users.each do |p| >> @pic<< Picture.where(:phrase_id => :route , :culture_id => >> p.culture_id).first >> >> end >> >> @pic.compact! >> send_data @pic.image, :type => ''image/png'', :disposition => ''inline'' >> >> end >> >> >> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> >>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> Oh yes... sorry about that. >>>> I assumed that you will find picture for every query. >>>> >>>> You can try this instead: >>>> def index >>>> @users= User.all >>>> @pic = [] >>>> >>>> @users.each do |p| >>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>> p.culture_id).limit(1) >>>> end >>>> @pic.compact! >>>> end >>>> >>>> by calling compact! on the array, we will eliminate all nil object. >>>> >>>> On another note, are you sure, this is what you want to do? If you have >>>> 100 users, it will fire 100 sql queries which is not good. >>>> >>>> Yes i think i have that problem as well because if i remove "@users.each >>> do |p| " >>> and then it will cause undefined method of culture_id.. >>> plus when i call @pic.compact! , it gives me >>> >>> NoMethodError (You have a nil object when you didn''t expect it! >>> You might have expected an instance of Array. >>> The error occurred while evaluating nil.compact!): >>> app/controllers/patients_controller.rb:29:in `index'' >>> >>> what is mean? cuz i want to display picture on the browser too... >>> >>> please help... thank you very much >>> >>> Joanne >>> >>>> >>>> >>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>> >>>>> it does not work, it is complaining other error >>>>> >>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>> >>>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> Your index action should be something like this: >>>>>> >>>>>> def index >>>>>> @users= User.all >>>>>> @pic = [] >>>>>> >>>>>> @users.each do |p| >>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>> p.culture_id).limit(1) >>>>>> end >>>>>> end >>>>>> >>>>>> -- >>>>>> 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/-/B259TKI0970J. >>>>>> >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> -------------------------------- >>>>> >>>>> Thank you, >>>>> >>>>> Yen >>>>> >>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Chirag >>>> http://sumeruonrails.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. >>>> >>> >>> >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > > -- > 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. >-- Chirag http://sumeruonrails.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.
> > >> def index > >> @users= User.all > >> @pic= [] > > You would probably have fewer problems if you observed the Rails > naming conventions; e.g. > > @pictures = [] # plural > > @users.each do |user| > @pictures << Picture.where(:phrase_id => :route , :culture_id > =>user.culture_id).first > end > > @pictures.compact! > > Now it''s obvious that the next line makes no sense: > > send_data @pictures.image, :type => ''image/png'', :disposition > => ''inline'' > > An *array* of pictures doesn''t have an "image" attribute. > > because i want to take a value "image" from Picture modelwhat can i do ... I am really stuck now.. thanks Joanne -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://about.me/hassanschroeder twitter: @hassan -- 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.
> 1. Remove the send_data line, it isn''t required.Yes, it did remove it.> 2. Can you check if there are any records in your pictures table? Right now > it looks like it is returning nil. >Yes, It has 1 record in Picture table and 3 records in User Table> > On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> >> Can you paste what you have in your index method? >>> You should not be getting this error because we have already defined @pic >>> as an empty array. >>> >>> >> >> >>> def index >>> >>> @users= User.all >>> @pic= [] >>> >>> @users.each do |p| >>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>> p.culture_id).first >>> >>> end >>> >>> @pic.compact! >>> send_data @pic.image, :type => ''image/png'', :disposition => ''inline'' >>> >>> end >>> >>> >>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> >>>> >>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>> >>>>> Oh yes... sorry about that. >>>>> I assumed that you will find picture for every query. >>>>> >>>>> You can try this instead: >>>>> def index >>>>> @users= User.all >>>>> @pic = [] >>>>> >>>>> @users.each do |p| >>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>> p.culture_id).limit(1) >>>>> end >>>>> @pic.compact! >>>>> end >>>>> >>>>> by calling compact! on the array, we will eliminate all nil object. >>>>> >>>>> On another note, are you sure, this is what you want to do? If you have >>>>> 100 users, it will fire 100 sql queries which is not good. >>>>> >>>>> Yes i think i have that problem as well because if i remove "@users.each >>>> do |p| " >>>> and then it will cause undefined method of culture_id.. >>>> plus when i call @pic.compact! , it gives me >>>> >>>> NoMethodError (You have a nil object when you didn''t expect it! >>>> You might have expected an instance of Array. >>>> The error occurred while evaluating nil.compact!): >>>> app/controllers/patients_controller.rb:29:in `index'' >>>> >>>> what is mean? cuz i want to display picture on the browser too... >>>> >>>> please help... thank you very much >>>> >>>> Joanne >>>> >>>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>> >>>>>> it does not work, it is complaining other error >>>>>> >>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>> >>>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>> >>>>>>> Your index action should be something like this: >>>>>>> >>>>>>> def index >>>>>>> @users= User.all >>>>>>> @pic = [] >>>>>>> >>>>>>> @users.each do |p| >>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>> p.culture_id).limit(1) >>>>>>> end >>>>>>> end >>>>>>> -- >>>>>>> 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/-/B259TKI0970J. >>>>>>> >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> -------------------------------- >>>>>> >>>>>> Thank you, >>>>>> >>>>>> Yen >>>>>> >>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Chirag >>>>> http://sumeruonrails.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-/JYPxA39Uh5TLH3MbocFFw@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. >>>> >>> >>> >>> >>> -- >>> Chirag >>> http://sumeruonrails.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. >>> >> >> >> >> -- >> -------------------------------- >> >> Thank you, >> >> Yen >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- -------------------------------- Thank you, Yen -- 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 21 June 2011 16:31, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> ... > what can i do ... I am really stuck now..I think it might be a good idea for you to work through some Rails tutorials to understand the basics of Rails. The free-to-use-online tutorial railstutorial.org is good. It might seem that the tutorial does not lead to the application that you want to develop but if you work right through it you will learn a vast amount and will then be embarrassed to look back here at the questions you were asking :) Also take a good look at the Rails Guides. I mean a *good* look do not just skim through them. Again you will learn a lot and the time spent will be saved many times over. 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.
Not sure why it errors out now. Do you get the same error is it a different error this time? On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 1. Remove the send_data line, it isn''t required. > > Yes, it did remove it. > >> 2. Can you check if there are any records in your pictures table? Right >> now it looks like it is returning nil. >> > Yes, It has 1 record in Picture table and 3 records in User Table > > >> >> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> >>> Can you paste what you have in your index method? >>>> You should not be getting this error because we have already defined >>>> @pic as an empty array. >>>> >>>> >>> >>> >>>> def index >>>> >>>> @users= User.all >>>> @pic= [] >>>> >>>> @users.each do |p| >>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>> p.culture_id).first >>>> >>>> end >>>> >>>> @pic.compact! >>>> send_data @pic.image, :type => ''image/png'', :disposition => ''inline'' >>>> >>>> end >>>> >>>> >>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>> >>>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>> >>>>>> Oh yes... sorry about that. >>>>>> I assumed that you will find picture for every query. >>>>>> >>>>>> You can try this instead: >>>>>> def index >>>>>> @users= User.all >>>>>> @pic = [] >>>>>> >>>>>> @users.each do |p| >>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>> p.culture_id).limit(1) >>>>>> end >>>>>> @pic.compact! >>>>>> end >>>>>> >>>>>> by calling compact! on the array, we will eliminate all nil object. >>>>>> >>>>>> On another note, are you sure, this is what you want to do? If you >>>>>> have 100 users, it will fire 100 sql queries which is not good. >>>>>> >>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>> do |p| " >>>>> and then it will cause undefined method of culture_id.. >>>>> plus when i call @pic.compact! , it gives me >>>>> >>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>> You might have expected an instance of Array. >>>>> The error occurred while evaluating nil.compact!): >>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>> >>>>> what is mean? cuz i want to display picture on the browser too... >>>>> >>>>> please help... thank you very much >>>>> >>>>> Joanne >>>>> >>>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>> >>>>>>> it does not work, it is complaining other error >>>>>>> >>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>> >>>>>>> >>>>>>> >>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>> >>>>>>>> Your index action should be something like this: >>>>>>>> >>>>>>>> def index >>>>>>>> @users= User.all >>>>>>>> @pic = [] >>>>>>>> >>>>>>>> @users.each do |p| >>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>> p.culture_id).limit(1) >>>>>>>> end >>>>>>>> end >>>>>>>> -- >>>>>>>> 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/-/B259TKI0970J. >>>>>>>> >>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> -------------------------------- >>>>>>> >>>>>>> Thank you, >>>>>>> >>>>>>> Yen >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Chirag >>>>>> http://sumeruonrails.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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Chirag >>>> http://sumeruonrails.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. >>>> >>> >>> >>> >>> -- >>> -------------------------------- >>> >>> Thank you, >>> >>> Yen >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > > -- > 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. >-- Chirag http://sumeruonrails.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.
> Not sure why it errors out now. > Do you get the same error is it a different error this time? >this is my index def index @user= Users.all @pictograph = [] @user.each do |p| @pic= Picture.where(:phrase_id => :route , :culture_id => p.culturet_id).first @pic.compact! end end and my view is <td><%= image_tag url_for(:controller => "/users", :action => "index"), :width => "25px", :height => "25px"%></td> my error: Processing by UsersController#index as User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1 PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 Completed in 237ms NoMethodError (You have a nil object when you didn''t expect it! You might have expected an instance of Array. The error occurred while evaluating nil.compact!): app/controllers/users_controller.rb:27:in `block in index'' app/controllers/users_controller.rb:25:in `each'' app/controllers/users_controller.rb:25:in `index''> > On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> 1. Remove the send_data line, it isn''t required. >> >> Yes, it did remove it. >> >>> 2. Can you check if there are any records in your pictures table? Right >>> now it looks like it is returning nil. >>> >> Yes, It has 1 record in Picture table and 3 records in User Table >> >> >>> >>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> >>>> >>>> Can you paste what you have in your index method? >>>>> You should not be getting this error because we have already defined >>>>> @pic as an empty array. >>>>> >>>>> >>>> >>>> >>>>> def index >>>>> >>>>> @users= User.all >>>>> @pic= [] >>>>> >>>>> @users.each do |p| >>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>> p.culture_id).first >>>>> >>>>> end >>>>> >>>>> @pic.compact! >>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>> ''inline'' >>>>> >>>>> end >>>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>> >>>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>> >>>>>>> Oh yes... sorry about that. >>>>>>> I assumed that you will find picture for every query. >>>>>>> >>>>>>> You can try this instead: >>>>>>> def index >>>>>>> @users= User.all >>>>>>> @pic = [] >>>>>>> >>>>>>> @users.each do |p| >>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>> p.culture_id).limit(1) >>>>>>> end >>>>>>> @pic.compact! >>>>>>> end >>>>>>> >>>>>>> by calling compact! on the array, we will eliminate all nil object. >>>>>>> >>>>>>> On another note, are you sure, this is what you want to do? If you >>>>>>> have 100 users, it will fire 100 sql queries which is not good. >>>>>>> >>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>> do |p| " >>>>>> and then it will cause undefined method of culture_id.. >>>>>> plus when i call @pic.compact! , it gives me >>>>>> >>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>> You might have expected an instance of Array. >>>>>> The error occurred while evaluating nil.compact!): >>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>> >>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>> >>>>>> please help... thank you very much >>>>>> >>>>>> Joanne >>>>>> >>>>>>> >>>>>>> >>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>> >>>>>>>> it does not work, it is complaining other error >>>>>>>> >>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>> >>>>>>>>> Your index action should be something like this: >>>>>>>>> >>>>>>>>> def index >>>>>>>>> @users= User.all >>>>>>>>> @pic = [] >>>>>>>>> >>>>>>>>> @users.each do |p| >>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>> p.culture_id).limit(1) >>>>>>>>> end >>>>>>>>> end >>>>>>>>> -- >>>>>>>>> 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/-/B259TKI0970J. >>>>>>>>> >>>>>>>>> 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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> -------------------------------- >>>>>>>> >>>>>>>> Thank you, >>>>>>>> >>>>>>>> Yen >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Chirag >>>>>>> http://sumeruonrails.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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Chirag >>>>> http://sumeruonrails.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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> -------------------------------- >>>> >>>> Thank you, >>>> >>>> Yen >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Chirag >>> http://sumeruonrails.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. >>> >> >> >> >> -- >> -------------------------------- >> >> Thank you, >> >> Yen >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- -------------------------------- Thank you, Yen -- 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.
Oh, so you are trying to get the image url from the user''s index action? If yes, that''s not correct. You should instead have a different method name and should request for image url of only one specific user. It would help in cleaning up the code and solve this issue faster, if you can tell me what exactly you are trying to do. On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Not sure why it errors out now. >> Do you get the same error is it a different error this time? >> > > this is my index > > def index > @user= Users.all > @pictograph = [] > > @user.each do |p| > @pic= Picture.where(:phrase_id => :route , :culture_id => > p.culturet_id).first > @pic.compact! > end > end > > and my view is > > <td><%= image_tag url_for(:controller => "/users", :action => "index"), > :width => "25px", :height => "25px"%></td> > > my error: > Processing by UsersController#index as > User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 > LIMIT 1 > PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE > "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 > Completed in 237ms > > > NoMethodError (You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.compact!): > app/controllers/users_controller.rb:27:in `block in index'' > app/controllers/users_controller.rb:25:in `each'' > app/controllers/users_controller.rb:25:in `index'' > > >> >> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> 1. Remove the send_data line, it isn''t required. >>> >>> Yes, it did remove it. >>> >>>> 2. Can you check if there are any records in your pictures table? Right >>>> now it looks like it is returning nil. >>>> >>> Yes, It has 1 record in Picture table and 3 records in User Table >>> >>> >>>> >>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>> >>>>> >>>>> >>>>> Can you paste what you have in your index method? >>>>>> You should not be getting this error because we have already defined >>>>>> @pic as an empty array. >>>>>> >>>>>> >>>>> >>>>> >>>>>> def index >>>>>> >>>>>> @users= User.all >>>>>> @pic= [] >>>>>> >>>>>> @users.each do |p| >>>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>>> p.culture_id).first >>>>>> >>>>>> end >>>>>> >>>>>> @pic.compact! >>>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>>> ''inline'' >>>>>> >>>>>> end >>>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>> >>>>>>> >>>>>>> >>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>> >>>>>>>> Oh yes... sorry about that. >>>>>>>> I assumed that you will find picture for every query. >>>>>>>> >>>>>>>> You can try this instead: >>>>>>>> def index >>>>>>>> @users= User.all >>>>>>>> @pic = [] >>>>>>>> >>>>>>>> @users.each do |p| >>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>> p.culture_id).limit(1) >>>>>>>> end >>>>>>>> @pic.compact! >>>>>>>> end >>>>>>>> >>>>>>>> by calling compact! on the array, we will eliminate all nil object. >>>>>>>> >>>>>>>> On another note, are you sure, this is what you want to do? If you >>>>>>>> have 100 users, it will fire 100 sql queries which is not good. >>>>>>>> >>>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>>> do |p| " >>>>>>> and then it will cause undefined method of culture_id.. >>>>>>> plus when i call @pic.compact! , it gives me >>>>>>> >>>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>>> You might have expected an instance of Array. >>>>>>> The error occurred while evaluating nil.compact!): >>>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>>> >>>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>>> >>>>>>> please help... thank you very much >>>>>>> >>>>>>> Joanne >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>> >>>>>>>>> it does not work, it is complaining other error >>>>>>>>> >>>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>> >>>>>>>>>> Your index action should be something like this: >>>>>>>>>> >>>>>>>>>> def index >>>>>>>>>> @users= User.all >>>>>>>>>> @pic = [] >>>>>>>>>> >>>>>>>>>> @users.each do |p| >>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>> end >>>>>>>>>> end >>>>>>>>>> -- >>>>>>>>>> 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/-/B259TKI0970J. >>>>>>>>>> >>>>>>>>>> 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. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> -------------------------------- >>>>>>>>> >>>>>>>>> Thank you, >>>>>>>>> >>>>>>>>> Yen >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> 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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Chirag >>>>>>>> http://sumeruonrails.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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Chirag >>>>>> http://sumeruonrails.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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> -------------------------------- >>>>> >>>>> Thank you, >>>>> >>>>> Yen >>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Chirag >>>> http://sumeruonrails.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. >>>> >>> >>> >>> >>> -- >>> -------------------------------- >>> >>> Thank you, >>> >>> Yen >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > > -- > 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. >-- Chirag http://sumeruonrails.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.
> Oh, so you are trying to get the image url from the user''s index action? > If yes, that''s not correct. >yes, i am trying to get image url from db> > You should instead have a different method name and should request for > image url of only one specific user. >I have def show to get specific user def show @user= User.find_by_id(params[:id]) end> > It would help in cleaning up the code and solve this issue faster, if you > can tell me what exactly you are trying to do. >I want take a value image from Picture table with specific user and display it on the screen. can u help me... thanks :X so much much.. Joanne> >> On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> Not sure why it errors out now. >>> Do you get the same error is it a different error this time? >>> >> >> this is my index >> >> def index >> @user= Users.all >> @pictograph = [] >> >> @user.each do |p| >> @pic= Picture.where(:phrase_id => :route , :culture_id => >> p.culturet_id).first >> @pic.compact! >> end >> end >> >> and my view is >> >> <td><%= image_tag url_for(:controller => "/users", :action => "index"), >> :width => "25px", :height => "25px"%></td> >> >> my error: >> Processing by UsersController#index as >> User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 >> LIMIT 1 >> PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE >> "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 >> Completed in 237ms >> >> >> NoMethodError (You have a nil object when you didn''t expect it! >> You might have expected an instance of Array. >> The error occurred while evaluating nil.compact!): >> app/controllers/users_controller.rb:27:in `block in index'' >> app/controllers/users_controller.rb:25:in `each'' >> app/controllers/users_controller.rb:25:in `index'' >> >> >>> >>> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> >>>> 1. Remove the send_data line, it isn''t required. >>>> >>>> Yes, it did remove it. >>>> >>>>> 2. Can you check if there are any records in your pictures table? Right >>>>> now it looks like it is returning nil. >>>>> >>>> Yes, It has 1 record in Picture table and 3 records in User Table >>>> >>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>> >>>>>> >>>>>> >>>>>> Can you paste what you have in your index method? >>>>>>> You should not be getting this error because we have already defined >>>>>>> @pic as an empty array. >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>>> def index >>>>>>> >>>>>>> @users= User.all >>>>>>> @pic= [] >>>>>>> >>>>>>> @users.each do |p| >>>>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>>>> p.culture_id).first >>>>>>> >>>>>>> end >>>>>>> >>>>>>> @pic.compact! >>>>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>>>> ''inline'' >>>>>>> >>>>>>> end >>>>>>> >>>>>>> >>>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>> >>>>>>>>> Oh yes... sorry about that. >>>>>>>>> I assumed that you will find picture for every query. >>>>>>>>> >>>>>>>>> You can try this instead: >>>>>>>>> def index >>>>>>>>> @users= User.all >>>>>>>>> @pic = [] >>>>>>>>> >>>>>>>>> @users.each do |p| >>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>> p.culture_id).limit(1) >>>>>>>>> end >>>>>>>>> @pic.compact! >>>>>>>>> end >>>>>>>>> >>>>>>>>> by calling compact! on the array, we will eliminate all nil object. >>>>>>>>> >>>>>>>>> On another note, are you sure, this is what you want to do? If you >>>>>>>>> have 100 users, it will fire 100 sql queries which is not good. >>>>>>>>> >>>>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>>>> do |p| " >>>>>>>> and then it will cause undefined method of culture_id.. >>>>>>>> plus when i call @pic.compact! , it gives me >>>>>>>> >>>>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>>>> You might have expected an instance of Array. >>>>>>>> The error occurred while evaluating nil.compact!): >>>>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>>>> >>>>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>>>> >>>>>>>> please help... thank you very much >>>>>>>> >>>>>>>> Joanne >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>>> >>>>>>>>>> it does not work, it is complaining other error >>>>>>>>>> >>>>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>> >>>>>>>>>>> Your index action should be something like this: >>>>>>>>>>> >>>>>>>>>>> def index >>>>>>>>>>> @users= User.all >>>>>>>>>>> @pic = [] >>>>>>>>>>> >>>>>>>>>>> @users.each do |p| >>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>>> end >>>>>>>>>>> end >>>>>>>>>>> -- >>>>>>>>>>> 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/-/B259TKI0970J. >>>>>>>>>>> >>>>>>>>>>> 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. >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> -------------------------------- >>>>>>>>>> >>>>>>>>>> Thank you, >>>>>>>>>> >>>>>>>>>> Yen >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> 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. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> Chirag >>>>>>>>> http://sumeruonrails.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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Chirag >>>>>>> http://sumeruonrails.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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> -------------------------------- >>>>>> >>>>>> Thank you, >>>>>> >>>>>> Yen >>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Chirag >>>>> http://sumeruonrails.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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> -------------------------------- >>>> >>>> Thank you, >>>> >>>> Yen >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Chirag >>> http://sumeruonrails.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. >>> >> >> >> >> -- >> -------------------------------- >> >> Thank you, >> >> Yen >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- 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.
Ok, that''s clear now. Do you use pastie (http://pastie.org/) or gist (https://gist.github.com/)? If yes, can you paste following on any of them and reply with link? #models User Picture #controllers UsersController #views users/index On Tue, Jun 21, 2011 at 9:37 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Oh, so you are trying to get the image url from the user''s index action? >> If yes, that''s not correct. >> > yes, i am trying to get image url from db > >> >> You should instead have a different method name and should request for >> image url of only one specific user. >> > I have def show to get specific user > > def show > @user= User.find_by_id(params[:id]) > end > >> >> It would help in cleaning up the code and solve this issue faster, if you >> can tell me what exactly you are trying to do. >> > > I want take a value image from Picture table with specific user and display > it on the screen. > can u help me... thanks :X so much much.. > > > Joanne > >> >> > >> On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> Not sure why it errors out now. >>>> Do you get the same error is it a different error this time? >>>> >>> >>> this is my index >>> >>> def index >>> @user= Users.all >>> @pictograph = [] >>> >>> @user.each do |p| >>> @pic= Picture.where(:phrase_id => :route , :culture_id => >>> p.culturet_id).first >>> @pic.compact! >>> end >>> end >>> >>> and my view is >>> >>> <td><%= image_tag url_for(:controller => "/users", :action => "index"), >>> :width => "25px", :height => "25px"%></td> >>> >>> my error: >>> Processing by UsersController#index as >>> User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = 1 >>> LIMIT 1 >>> PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE >>> "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 >>> Completed in 237ms >>> >>> >>> NoMethodError (You have a nil object when you didn''t expect it! >>> You might have expected an instance of Array. >>> The error occurred while evaluating nil.compact!): >>> app/controllers/users_controller.rb:27:in `block in index'' >>> app/controllers/users_controller.rb:25:in `each'' >>> app/controllers/users_controller.rb:25:in `index'' >>> >>> >>>> >>>> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>> >>>>> >>>>> 1. Remove the send_data line, it isn''t required. >>>>> >>>>> Yes, it did remove it. >>>>> >>>>>> 2. Can you check if there are any records in your pictures table? >>>>>> Right now it looks like it is returning nil. >>>>>> >>>>> Yes, It has 1 record in Picture table and 3 records in User Table >>>>> >>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>> >>>>>>> >>>>>>> >>>>>>> Can you paste what you have in your index method? >>>>>>>> You should not be getting this error because we have already defined >>>>>>>> @pic as an empty array. >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>>> def index >>>>>>>> >>>>>>>> @users= User.all >>>>>>>> @pic= [] >>>>>>>> >>>>>>>> @users.each do |p| >>>>>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>>>>> p.culture_id).first >>>>>>>> >>>>>>>> end >>>>>>>> >>>>>>>> @pic.compact! >>>>>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>>>>> ''inline'' >>>>>>>> >>>>>>>> end >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>> >>>>>>>>>> Oh yes... sorry about that. >>>>>>>>>> I assumed that you will find picture for every query. >>>>>>>>>> >>>>>>>>>> You can try this instead: >>>>>>>>>> def index >>>>>>>>>> @users= User.all >>>>>>>>>> @pic = [] >>>>>>>>>> >>>>>>>>>> @users.each do |p| >>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>> end >>>>>>>>>> @pic.compact! >>>>>>>>>> end >>>>>>>>>> >>>>>>>>>> by calling compact! on the array, we will eliminate all nil >>>>>>>>>> object. >>>>>>>>>> >>>>>>>>>> On another note, are you sure, this is what you want to do? If you >>>>>>>>>> have 100 users, it will fire 100 sql queries which is not good. >>>>>>>>>> >>>>>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>>>>> do |p| " >>>>>>>>> and then it will cause undefined method of culture_id.. >>>>>>>>> plus when i call @pic.compact! , it gives me >>>>>>>>> >>>>>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>>>>> You might have expected an instance of Array. >>>>>>>>> The error occurred while evaluating nil.compact!): >>>>>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>>>>> >>>>>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>>>>> >>>>>>>>> please help... thank you very much >>>>>>>>> >>>>>>>>> Joanne >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>>>> >>>>>>>>>>> it does not work, it is complaining other error >>>>>>>>>>> >>>>>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>>> >>>>>>>>>>>> Your index action should be something like this: >>>>>>>>>>>> >>>>>>>>>>>> def index >>>>>>>>>>>> @users= User.all >>>>>>>>>>>> @pic = [] >>>>>>>>>>>> >>>>>>>>>>>> @users.each do |p| >>>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>>>> end >>>>>>>>>>>> end >>>>>>>>>>>> -- >>>>>>>>>>>> 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/-/B259TKI0970J >>>>>>>>>>>> . >>>>>>>>>>>> >>>>>>>>>>>> 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. >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> -------------------------------- >>>>>>>>>>> >>>>>>>>>>> Thank you, >>>>>>>>>>> >>>>>>>>>>> Yen >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> 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. >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Chirag >>>>>>>>>> http://sumeruonrails.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. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> 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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Chirag >>>>>>>> http://sumeruonrails.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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> -------------------------------- >>>>>>> >>>>>>> Thank you, >>>>>>> >>>>>>> Yen >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Chirag >>>>>> http://sumeruonrails.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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> -------------------------------- >>>>> >>>>> Thank you, >>>>> >>>>> Yen >>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Chirag >>>> http://sumeruonrails.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. >>>> >>> >>> >>> >>> -- >>> -------------------------------- >>> >>> Thank you, >>> >>> Yen >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > -- > 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. >-- Chirag http://sumeruonrails.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.
> Ok, that''s clear now. > > Do you use pastie (http://pastie.org/) or gist (https://gist.github.com/)? > If yes, can you paste following on any of them and reply with link? > No, I am using that.. >> #models > User >id name address culture_id Picture>id image(binary) phrase_id culture_id Culture id phrase_id> > #controllers > UsersController >def index @user= User.all @pic= [] @user.each do |p| @pic<< Picture.where(:phrase_id => :route , :culture_id => p.culture_id).first @pic.compact! end end def show @user= User.find_by_id(params[:id]) end end> > #views > users/index ><td><%= image_tag url_for(:controller => "/patients", :action => "index"), :width => "25px", :height => "25px"%></td>> > On Tue, Jun 21, 2011 at 9:37 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> >> Oh, so you are trying to get the image url from the user''s index action? >>> If yes, that''s not correct. >>> >> yes, i am trying to get image url from db >> >>> >>> You should instead have a different method name and should request for >>> image url of only one specific user. >>> >> I have def show to get specific user >> >> def show >> @user= User.find_by_id(params[:id]) >> end >> >>> >>> It would help in cleaning up the code and solve this issue faster, if you >>> can tell me what exactly you are trying to do. >>> >> >> I want take a value image from Picture table with specific user and >> display it on the screen. >> can u help me... thanks :X so much much.. >> >> >> Joanne >> >>> >>> >> >>> On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>> >>>> >>>> Not sure why it errors out now. >>>>> Do you get the same error is it a different error this time? >>>>> >>>> >>>> this is my index >>>> >>>> def index >>>> @user= Users.all >>>> @pictograph = [] >>>> >>>> @user.each do |p| >>>> @pic= Picture.where(:phrase_id => :route , :culture_id => >>>> p.culturet_id).first >>>> @pic.compact! >>>> end >>>> end >>>> >>>> and my view is >>>> >>>> <td><%= image_tag url_for(:controller => "/users", :action => "index"), >>>> :width => "25px", :height => "25px"%></td> >>>> >>>> my error: >>>> Processing by UsersController#index as >>>> User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" >>>> 1 LIMIT 1 >>>> PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE >>>> "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 >>>> Completed in 237ms >>>> >>>> >>>> NoMethodError (You have a nil object when you didn''t expect it! >>>> You might have expected an instance of Array. >>>> The error occurred while evaluating nil.compact!): >>>> app/controllers/users_controller.rb:27:in `block in index'' >>>> app/controllers/users_controller.rb:25:in `each'' >>>> app/controllers/users_controller.rb:25:in `index'' >>>> >>>> >>>>> >>>>> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>> >>>>>> >>>>>> 1. Remove the send_data line, it isn''t required. >>>>>> >>>>>> Yes, it did remove it. >>>>>> >>>>>>> 2. Can you check if there are any records in your pictures table? >>>>>>> Right now it looks like it is returning nil. >>>>>>> >>>>>> Yes, It has 1 record in Picture table and 3 records in User Table >>>>>> >>>>>> >>>>>>> >>>>>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Can you paste what you have in your index method? >>>>>>>>> You should not be getting this error because we have already >>>>>>>>> defined @pic as an empty array. >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>>> def index >>>>>>>>> >>>>>>>>> @users= User.all >>>>>>>>> @pic= [] >>>>>>>>> >>>>>>>>> @users.each do |p| >>>>>>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>> p.culture_id).first >>>>>>>>> >>>>>>>>> end >>>>>>>>> >>>>>>>>> @pic.compact! >>>>>>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>>>>>> ''inline'' >>>>>>>>> >>>>>>>>> end >>>>>>>>> >>>>>>>>> >>>>>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>> >>>>>>>>>>> Oh yes... sorry about that. >>>>>>>>>>> I assumed that you will find picture for every query. >>>>>>>>>>> >>>>>>>>>>> You can try this instead: >>>>>>>>>>> def index >>>>>>>>>>> @users= User.all >>>>>>>>>>> @pic = [] >>>>>>>>>>> >>>>>>>>>>> @users.each do |p| >>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>>> end >>>>>>>>>>> @pic.compact! >>>>>>>>>>> end >>>>>>>>>>> >>>>>>>>>>> by calling compact! on the array, we will eliminate all nil >>>>>>>>>>> object. >>>>>>>>>>> >>>>>>>>>>> On another note, are you sure, this is what you want to do? If >>>>>>>>>>> you have 100 users, it will fire 100 sql queries which is not good. >>>>>>>>>>> >>>>>>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>>>>>> do |p| " >>>>>>>>>> and then it will cause undefined method of culture_id.. >>>>>>>>>> plus when i call @pic.compact! , it gives me >>>>>>>>>> >>>>>>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>>>>>> You might have expected an instance of Array. >>>>>>>>>> The error occurred while evaluating nil.compact!): >>>>>>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>>>>>> >>>>>>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>>>>>> >>>>>>>>>> please help... thank you very much >>>>>>>>>> >>>>>>>>>> Joanne >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org >>>>>>>>>>> > wrote: >>>>>>>>>>> >>>>>>>>>>>> it does not work, it is complaining other error >>>>>>>>>>>> >>>>>>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>>>> >>>>>>>>>>>>> Your index action should be something like this: >>>>>>>>>>>>> >>>>>>>>>>>>> def index >>>>>>>>>>>>> @users= User.all >>>>>>>>>>>>> @pic = [] >>>>>>>>>>>>> >>>>>>>>>>>>> @users.each do |p| >>>>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>>>>> end >>>>>>>>>>>>> end >>>>>>>>>>>>> -- >>>>>>>>>>>>> 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/-/B259TKI0970J >>>>>>>>>>>>> . >>>>>>>>>>>>> >>>>>>>>>>>>> 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. >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> -------------------------------- >>>>>>>>>>>> >>>>>>>>>>>> Thank you, >>>>>>>>>>>> >>>>>>>>>>>> Yen >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> 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. >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> Chirag >>>>>>>>>>> http://sumeruonrails.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. >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> 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. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> Chirag >>>>>>>>> http://sumeruonrails.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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> -------------------------------- >>>>>>>> >>>>>>>> Thank you, >>>>>>>> >>>>>>>> Yen >>>>>>>> >>>>>>>> -- >>>>>>>> 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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Chirag >>>>>>> http://sumeruonrails.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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> -------------------------------- >>>>>> >>>>>> Thank you, >>>>>> >>>>>> Yen >>>>>> >>>>>> -- >>>>>> 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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Chirag >>>>> http://sumeruonrails.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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> -------------------------------- >>>> >>>> Thank you, >>>> >>>> Yen >>>> >>>> -- >>>> 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. >>>> >>> >>> >>> >>> -- >>> Chirag >>> http://sumeruonrails.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. >>> >> >> >> -- >> 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. >> > > > > -- > Chirag > http://sumeruonrails.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. >-- -------------------------------- Thank you, Yen -- 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 Tue, Jun 21, 2011 at 12:31 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ok, that''s clear now. >> >> Do you use pastie (http://pastie.org/) or gist (https://gist.github.com/ >> )? >> If yes, can you paste following on any of them and reply with link? >> No, I am using that.. >> > > > >> #models >> User >> > id > name > address > culture_id > > Picture >> > id > image(binary) > phrase_id > culture_id > > Culture > id > phrase_id > > > >> >> #controllers >> UsersController >> > > def index > @user= User.all > @pic= [] > @user.each do |p| > @pic<< Picture.where(:phrase_id => :route , :culture_id => > p.culture_id).first > @pic.compact! > > end > end > > > > > def show > @user= User.find_by_id(params[:id]) > end > > end > > >> >> #views >> users/index >> > > <td><%= image_tag url_for(:controller => "/users", :action => "index"), > :width => "25px", :height => "25px"%></td> > >> >> On Tue, Jun 21, 2011 at 9:37 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >>> >>> Oh, so you are trying to get the image url from the user''s index action? >>>> If yes, that''s not correct. >>>> >>> yes, i am trying to get image url from db >>> >>>> >>>> You should instead have a different method name and should request for >>>> image url of only one specific user. >>>> >>> I have def show to get specific user >>> >>> def show >>> @user= User.find_by_id(params[:id]) >>> end >>> >>>> >>>> It would help in cleaning up the code and solve this issue faster, if >>>> you can tell me what exactly you are trying to do. >>>> >>> >>> I want take a value image from Picture table with specific user and >>> display it on the screen. >>> can u help me... thanks :X so much much.. >>> >>> >>> Joanne >>> >>>> >>>> >>> >>>> On Tue, Jun 21, 2011 at 9:22 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>> >>>>> >>>>> Not sure why it errors out now. >>>>>> Do you get the same error is it a different error this time? >>>>>> >>>>> >>>>> this is my index >>>>> >>>>> def index >>>>> @user= Users.all >>>>> @pictograph = [] >>>>> >>>>> @user.each do |p| >>>>> @pic= Picture.where(:phrase_id => :route , :culture_id => >>>>> p.culturet_id).first >>>>> @pic.compact! >>>>> end >>>>> end >>>>> >>>>> and my view is >>>>> >>>>> <td><%= image_tag url_for(:controller => "/users", :action => "index"), >>>>> :width => "25px", :height => "25px"%></td> >>>>> >>>>> my error: >>>>> Processing by UsersController#index as >>>>> User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" >>>>> 1 LIMIT 1 >>>>> PictureLoad (7.0ms) SELECT "pictures".* FROM "pictures" WHERE >>>>> "pictures"."phrase_id" = ''route'' AND "pictures"."culturet_id" = 1 LIMIT 1 >>>>> Completed in 237ms >>>>> >>>>> >>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>> You might have expected an instance of Array. >>>>> The error occurred while evaluating nil.compact!): >>>>> app/controllers/users_controller.rb:27:in `block in index'' >>>>> app/controllers/users_controller.rb:25:in `each'' >>>>> app/controllers/users_controller.rb:25:in `index'' >>>>> >>>>> >>>>>> >>>>>> On Tue, Jun 21, 2011 at 9:05 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>> >>>>>>> >>>>>>> 1. Remove the send_data line, it isn''t required. >>>>>>> >>>>>>> Yes, it did remove it. >>>>>>> >>>>>>>> 2. Can you check if there are any records in your pictures table? >>>>>>>> Right now it looks like it is returning nil. >>>>>>>> >>>>>>> Yes, It has 1 record in Picture table and 3 records in User Table >>>>>>> >>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 21, 2011 at 8:35 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> Can you paste what you have in your index method? >>>>>>>>>> You should not be getting this error because we have already >>>>>>>>>> defined @pic as an empty array. >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>>> def index >>>>>>>>>> >>>>>>>>>> @users= User.all >>>>>>>>>> @pic= [] >>>>>>>>>> >>>>>>>>>> @users.each do |p| >>>>>>>>>> @pic<< Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>> p.culture_id).first >>>>>>>>>> >>>>>>>>>> end >>>>>>>>>> >>>>>>>>>> @pic.compact! >>>>>>>>>> send_data @pic.image, :type => ''image/png'', :disposition => >>>>>>>>>> ''inline'' >>>>>>>>>> >>>>>>>>>> end >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Tue, Jun 21, 2011 at 8:10 PM, joanne ta <joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote: >>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> On Tue, Jun 21, 2011 at 10:27 AM, Chirag Singhal < >>>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>>> >>>>>>>>>>>> Oh yes... sorry about that. >>>>>>>>>>>> I assumed that you will find picture for every query. >>>>>>>>>>>> >>>>>>>>>>>> You can try this instead: >>>>>>>>>>>> def index >>>>>>>>>>>> @users= User.all >>>>>>>>>>>> @pic = [] >>>>>>>>>>>> >>>>>>>>>>>> @users.each do |p| >>>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id => >>>>>>>>>>>> p.culture_id).limit(1) >>>>>>>>>>>> end >>>>>>>>>>>> @pic.compact! >>>>>>>>>>>> end >>>>>>>>>>>> >>>>>>>>>>>> by calling compact! on the array, we will eliminate all nil >>>>>>>>>>>> object. >>>>>>>>>>>> >>>>>>>>>>>> On another note, are you sure, this is what you want to do? If >>>>>>>>>>>> you have 100 users, it will fire 100 sql queries which is not good. >>>>>>>>>>>> >>>>>>>>>>>> Yes i think i have that problem as well because if i remove "@users.each >>>>>>>>>>> do |p| " >>>>>>>>>>> and then it will cause undefined method of culture_id.. >>>>>>>>>>> plus when i call @pic.compact! , it gives me >>>>>>>>>>> >>>>>>>>>>> NoMethodError (You have a nil object when you didn''t expect it! >>>>>>>>>>> You might have expected an instance of Array. >>>>>>>>>>> The error occurred while evaluating nil.compact!): >>>>>>>>>>> app/controllers/patients_controller.rb:29:in `index'' >>>>>>>>>>> >>>>>>>>>>> what is mean? cuz i want to display picture on the browser too... >>>>>>>>>>> >>>>>>>>>>> please help... thank you very much >>>>>>>>>>> >>>>>>>>>>> Joanne >>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> On Tue, Jun 21, 2011 at 7:42 PM, joanne ta < >>>>>>>>>>>> joanne0558-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>>>> >>>>>>>>>>>>> it does not work, it is complaining other error >>>>>>>>>>>>> >>>>>>>>>>>>> NoMethodError (undefined method `image'' for [nil]:Array): >>>>>>>>>>>>> app/controllers/patients_controller.rb:27:in `block in index'' >>>>>>>>>>>>> app/controllers/patients_controller.rb:25:in `each'' >>>>>>>>>>>>> app/controllers/patients_controller.rb:25:in `index'' >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> On Tue, Jun 21, 2011 at 9:57 AM, Chirag Singhal < >>>>>>>>>>>>> chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >>>>>>>>>>>>> >>>>>>>>>>>>>> Your index action should be something like this: >>>>>>>>>>>>>> >>>>>>>>>>>>>> def index >>>>>>>>>>>>>> @users= User.all >>>>>>>>>>>>>> @pic = [] >>>>>>>>>>>>>> >>>>>>>>>>>>>> @users.each do |p| >>>>>>>>>>>>>> @pic << Picture.where(:phrase_id => :route , :culture_id >>>>>>>>>>>>>> => p.culture_id).limit(1) >>>>>>>>>>>>>> end >>>>>>>>>>>>>> end >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> 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/-/B259TKI0970J >>>>>>>>>>>>>> . >>>>>>>>>>>>>> >>>>>>>>>>>>>> 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. >>>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> -- >>>>>>>>>>>>> -------------------------------- >>>>>>>>>>>>> >>>>>>>>>>>>> Thank you, >>>>>>>>>>>>> >>>>>>>>>>>>> Yen >>>>>>>>>>>>> >>>>>>>>>>>>> >>>>>>>>>>>>> -- >>>>>>>>>>>>> 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. >>>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> >>>>>>>>>>>> -- >>>>>>>>>>>> Chirag >>>>>>>>>>>> http://sumeruonrails.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. >>>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> -- >>>>>>>>>>> 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. >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Chirag >>>>>>>>>> http://sumeruonrails.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. >>>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> -- >>>>>>>>> -------------------------------- >>>>>>>>> >>>>>>>>> Thank you, >>>>>>>>> >>>>>>>>> Yen >>>>>>>>> >>>>>>>>> -- >>>>>>>>> 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. >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Chirag >>>>>>>> http://sumeruonrails.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. >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> -------------------------------- >>>>>>> >>>>>>> Thank you, >>>>>>> >>>>>>> Yen >>>>>>> >>>>>>> -- >>>>>>> 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. >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Chirag >>>>>> http://sumeruonrails.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. >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> -------------------------------- >>>>> >>>>> Thank you, >>>>> >>>>> Yen >>>>> >>>>> -- >>>>> 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-/JYPxA39Uh5TLH3MbocFFw@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. >>>>> >>>> >>>> >>>> >>>> -- >>>> Chirag >>>> http://sumeruonrails.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. >>>> >>> >>> >>> -- >>> 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. >>> >> >> >> >> -- >> Chirag >> http://sumeruonrails.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. >> > > > > -- > -------------------------------- > > Thank you, > > Yen > >-- -------------------------------- Thank you, Yen -- 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.
Ok, that''s clear now.> > Do you use pastie (http://pastie.org/) or gist (https://gist.github.com/)? > If yes, can you paste following on any of them and reply with link? > No, I am not using that.. >> #models > User >id name address culture_id Picture>id image(binary) phrase_id culture_id Culture id phrase_id> > #controllers > UsersController >def index @user= User.all @pic= [] @user.each do |p| @pic<< Picture.where(:phrase_id => :route , :culture_id => p.culture_id).first @pic.compact! end end def show @user= User.find_by_id(params[:id]) end end> > #views > users/index ><td><%= image_tag url_for(:controller => "/users", :action => "index"), :width => "25px", :height => "25px"%></td> -- 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.
Ok, some more questions: 1. So, you want to display an image of the culture associated with the user, right? 2. How are you uploading pictures to your database? -- 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/-/yC0telfib3kJ. 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 Tue, Jun 21, 2011 at 12:52 PM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Ok, some more questions: > 1. So, you want to display an image of the culture associated with the > user, right? >yes> 2. How are you uploading pictures to your database? >right now, i just using the sqlite manager to upload the blob.> -- > 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/-/yC0telfib3kJ. > > 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. >-- -------------------------------- Thank you, Yen -- 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.
Getting pretty late here, heading to bed. We can work on a cleaner solution tomorrow or others on the forum can help. For now, this quick and dirty solution should work: # In your view <% @users.each do |user| %> <td><%= user.name %></td> <td><%= image_tag url_for(:controller => "users", :action => "culture_image, :culture_id => user.culture_id, :phrase_id => ""), :width => "25px", :height => "25px"%></td> <% end %> Note that I haven''t put in a value for :phrase_id in the url, please substitute appropriate value there as required. # In your controller def index @user= User.all end def culture_image picture = Picture.where(:phrase_id => params[:phrase_id], :culture_id => params[:culture_id]).limit(1) if picture send_data picture.image, :type => ''image/png'', :disposition => ''inline'' else render :status => 404 end end Note that you may have to modify your routes to include the new method "culture_image"... something like this" resources :users do get :culture_image, :on => :collection end -- 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/-/amryLvSd4UEJ. 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.
thanks you so much.. Joanne On Tue, Jun 21, 2011 at 1:29 PM, Chirag Singhal <chirag.singhal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>wrote:> Getting pretty late here, heading to bed. We can work on a cleaner solution > tomorrow or others on the forum can help. > For now, this quick and dirty solution should work: > > # In your view > <% @users.each do |user| %> > <td><%= user.name %></td> > <td><%= image_tag url_for(:controller => "users", :action => > "culture_image, :culture_id => user.culture_id, :phrase_id => ""), :width => > "25px", :height => "25px"%></td> > <% end %> > > Note that I haven''t put in a value for :phrase_id in the url, please > substitute appropriate value there as required. > > # In your controller > def index > @user= User.all > end > > def culture_image > picture = Picture.where(:phrase_id => params[:phrase_id], :culture_id > => params[:culture_id]).limit(1) > if picture > send_data picture.image, :type => ''image/png'', :disposition => > ''inline'' > else > render :status => 404 > end > end > > Note that you may have to modify your routes to include the new method > "culture_image"... something like this" > resources :users do > get :culture_image, :on => :collection > end > > -- > 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/-/amryLvSd4UEJ. > > 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.
Is it working now? If not post the error and we''ll see how to get it to a good shape. -- 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/-/Zsl4h9cI2jkJ. 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.