I got the id of a "part" in variable "the_id". In a partial "_order_fields.html.erb" So I do this... @a = Part.find(the_id) I get this error... Couldn''t find Part without an ID So I also try... @a = Part.find(the_id.to_i) Get same error. If I do @a = Part.find(2), it works. But I need to do the "find" using a variable, instead of hard-coding the value. (I know I shouldn''t be doing this in a view and I know the code is ugly by Ruby programming standards but I''m testing to see if it works, then I''ll rename it) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 25 August 2011 17:34, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I got the id of a "part" in variable "the_id". In a partial > "_order_fields.html.erb"What value does "the_id" have if you add a breakpoint before the find and inspect it? -- 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.
Quoting Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>:> I got the id of a "part" in variable "the_id". In a partial > "_order_fields.html.erb" > > So I do this... > @a = Part.find(the_id) > > I get this error... > Couldn''t find Part without an ID >Uhh, are you sure the_id has a numeric value at that point in the view? You don''t say where or how it is set. Local controller variables are not shared with views, though controller instance variables are. And anything can be passed to a partial, though not regular view through the :locals hash. HTH, Jeffrey -- 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.
Ah! found the solution: should''ve used "find_by_id", instead of just "find". http://stackoverflow.com/questions/1593120/variable-passing-to-find-function-in-rails-2 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
So, I do find the "part", using a = Part.find_by_id(the_id) If I do <%= debug a %> I get... ---------------------- attributes: name: Western Digital - Caviar GP 500GB Internal Hard Drive created_at: 2011-08-23 18:54:12.214873 cost: 49.99 updated_at: 2011-08-23 18:54:12.214873 id: 2 [...] ------------------- but if I do a.cost I get error... undefined method `cost'' for nil:NilClass How is it going to be a nil class? If I do a.class I get "Part", then it''s NOT a nil class. It''s weird, if I do exactly the same thing in the console a.cost does work. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This is very weird, even if I do a.methods, "cost" is there! -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This is making me crazy, even if I do... <%= a %> I get... #<Part:0x7f2fe2bf4cf8> But as soon as I try to access the cost or name attributes I get... undefined method `cost'' for nil:NilClass and it''s NOOT NIIILL!!!>:(-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Thu, Aug 25, 2011 at 1:18 PM, Leonel *.* <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This is making me crazy, even if I do... > <%= a %> > > I get... > #<Part:0x7f2fe2bf4cf8> > > But as soon as I try to access the cost or name attributes I get... > undefined method `cost'' for nil:NilClass > > and it''s NOOT NIIILL!!! > > >:( > >Can you pastebin your controller / view code? -- 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.
Leonel *.* wrote in post #1018495:> So, I do find the "part", using a = Part.find_by_id(the_id) > > If I do <%= debug a %> I get... > ---------------------- > attributes: > name: Western Digital - Caviar GP 500GB Internal Hard Drive > created_at: 2011-08-23 18:54:12.214873 > cost: 49.99 > updated_at: 2011-08-23 18:54:12.214873 > id: 2 > [...] > ------------------- > > but if I do > a.cost > > I get error... > undefined method `cost'' for nil:NilClass > > How is it going to be a nil class? If I do a.class I get "Part", then > it''s NOT a nil class. > > It''s weird, if I do exactly the same thing in the console a.cost does > work.Do you get an error if you do this: <% part = Part.find_by_id(the_id) part.cost %> -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 25, 6:18 pm, "Leonel *.*" <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> This is making me crazy, even if I do... > <%= a %> > > I get... > #<Part:0x7f2fe2bf4cf8> > > But as soon as I try to access the cost or name attributes I get... > undefined method `cost'' for nil:NilClass >Can you post the entirety of what''s in your view? Fred> and it''s NOOT NIIILL!!! > > >:( > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.